bin: move memaslap to contrib
[m6w6/libmemcached] / src / bin / contrib / memaslap / ms_thread.h
1 /*
2 +--------------------------------------------------------------------+
3 | libmemcached - C/C++ Client Library for memcached |
4 +--------------------------------------------------------------------+
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted under the terms of the BSD license. |
7 | You should have received a copy of the license in a bundled file |
8 | named LICENSE; in case you did not receive a copy you can review |
9 | the terms online at: https://opensource.org/licenses/BSD-3-Clause |
10 +--------------------------------------------------------------------+
11 | Copyright (c) 2006-2014 Brian Aker https://datadifferential.com/ |
12 | Copyright (c) 2020 Michael Wallner <mike@php.net> |
13 +--------------------------------------------------------------------+
14 */
15
16 #ifndef MS_THREAD_H
17 #define MS_THREAD_H
18
19 #include <pthread.h>
20 #include <sched.h>
21 #include "ms_conn.h"
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26
27 /** Time relative to server start. Smaller than time_t on 64-bit systems. */
28 typedef unsigned int rel_time_t;
29
30 /* Used to store the context of each thread */
31 typedef struct thread_ctx {
32 uint32_t thd_idx; /* the thread index */
33 uint32_t nconns; /* how many connections included by the thread */
34 uint32_t srv_idx; /* index of the thread */
35 int tps_perconn; /* expected throughput per connection */
36 int64_t exec_num_perconn; /* execute number per connection */
37 pthread_t pth_id;
38 } ms_thread_ctx_t;
39
40 /* Used to store the private variables of each thread */
41 typedef struct thread {
42 ms_conn_t *conn; /* conn array to store all the conn in the thread */
43 uint32_t nactive_conn; /* how many connects are active */
44
45 ms_thread_ctx_t *thread_ctx; /* thread context from the caller */
46 struct event_base *base; /* libevent handler created by this thread */
47
48 rel_time_t curr_time; /* current time */
49 struct event clock_event; /* clock event to time each one second */
50 bool initialized; /* whether clock_event has been initialized */
51
52 struct timeval startup_time; /* start time of the thread */
53 } ms_thread_t;
54
55 /* initialize threads */
56 void ms_thread_init(void);
57
58 /* cleanup some resource of threads when all the threads exit */
59 void ms_thread_cleanup(void);
60
61 #ifdef __cplusplus
62 }
63 #endif
64
65 #endif /* end of MS_THREAD_H */