38 printf(
"%s -- %8ld thread tasks / sec -- (at %d, dt %d, bl %zd) -- %zd\n",
44 #define ATOMIC_BOOL_COMPARE_AND_SWAP(PTR, OLD, NEW) \
45 (__sync_bool_compare_and_swap(PTR, OLD, NEW))
48 #define SPIN_ADJ(F, ADJ) \
52 if (ATOMIC_BOOL_COMPARE_AND_SWAP(&F, v, v + ADJ)) { \
67 env *e = (env *)udata;
68 if (e->count ==
limit) {
72 if ((e->count & ((1 << 16) - 1)) == 0) {
73 printf(
"count: %zd on %p\n", e->count, (
void *)pthread_self());
84 int main(
int argc,
char **argv) {
86 uint8_t max_threads = 8;
88 char *sz2_env = getenv(
"SZ2");
89 char *max_threads_env = getenv(
"MAX_THREADS");
90 char *limit_env = getenv(
"LIMIT");
91 if (sz2_env) { sz2 = atoi(sz2_env); }
92 if (max_threads_env) { max_threads = atoi(max_threads_env); }
93 if (limit_env) {
limit = atol(limit_env); }
96 printf(
"too many threads\n");
110 gettimeofday(&tv, NULL);
111 time_t last_sec = tv.tv_sec;
112 size_t counterpressure = 0;
117 memset(&tasks, 0,
sizeof(tasks));
119 for (
int i = 0; i < max_threads; i++) {
120 envs[i] = (env){ .t = t, .task = &tasks[i], .count = 0, };
130 printf(
"waiting...\n");
133 gettimeofday(&tv, NULL);
134 if (tv.tv_sec > last_sec) {
135 last_sec = tv.tv_sec;
threadpool_task_cb * task
Configuration for thread pool.
static void dump_stats(const char *prefix, struct threadpool_info *stats, size_t ticks)
Internal threadpool state.
static void task_cb(void *udata)
int main(int argc, char **argv)
uint8_t task_ringbuf_size2
struct threadpool * Threadpool_Init(struct threadpool_config *cfg)
Initialize a threadpool, according to a config.
Statistics about the current state of the threadpool.
static size_t completed_count
void Threadpool_Stats(struct threadpool *t, struct threadpool_info *info)
If TI is non-NULL, fill out some statistics about the operating state of the thread pool...
bool Threadpool_Schedule(struct threadpool *t, struct threadpool_task *task, size_t *pushback)
Schedule a task in the threadpool.