Lines Matching refs:stw
27 struct _IWSTW *stw = op; in worker_fn() local
28 assert(stw); in worker_fn()
29 pthread_barrier_wait(&stw->brr); in worker_fn()
35 pthread_mutex_lock(&stw->mtx); in worker_fn()
36 if (stw->head) { in worker_fn()
37 struct _TASK *h = stw->head; in worker_fn()
40 stw->head = h->next; in worker_fn()
41 if (stw->tail == h) { in worker_fn()
42 stw->tail = stw->head; in worker_fn()
44 --stw->cnt; in worker_fn()
47 pthread_mutex_unlock(&stw->mtx); in worker_fn()
53 pthread_mutex_lock(&stw->mtx); in worker_fn()
54 if (stw->head) { in worker_fn()
55 pthread_mutex_unlock(&stw->mtx); in worker_fn()
57 } else if (stw->shutdown) { in worker_fn()
58 pthread_mutex_unlock(&stw->mtx); in worker_fn()
61 pthread_cond_wait(&stw->cond, &stw->mtx); in worker_fn()
62 pthread_mutex_unlock(&stw->mtx); in worker_fn()
71 IWSTW stw = *stwp; in iwstw_shutdown() local
72 pthread_mutex_lock(&stw->mtx); in iwstw_shutdown()
73 if (stw->shutdown) { in iwstw_shutdown()
74 pthread_mutex_unlock(&stw->mtx); in iwstw_shutdown()
78 struct _TASK *t = stw->head; in iwstw_shutdown()
84 stw->head = 0; in iwstw_shutdown()
85 stw->tail = 0; in iwstw_shutdown()
86 stw->cnt = 0; in iwstw_shutdown()
88 stw->shutdown = true; in iwstw_shutdown()
89 pthread_cond_broadcast(&stw->cond); in iwstw_shutdown()
90 pthread_mutex_unlock(&stw->mtx); in iwstw_shutdown()
91 int rci = pthread_join(stw->thr, 0); in iwstw_shutdown()
96 pthread_barrier_destroy(&stw->brr); in iwstw_shutdown()
97 pthread_cond_destroy(&stw->cond); in iwstw_shutdown()
98 pthread_mutex_destroy(&stw->mtx); in iwstw_shutdown()
99 free(stw); in iwstw_shutdown()
103 iwrc iwstw_schedule(IWSTW stw, iwstw_task_f fn, void *arg) { in iwstw_schedule() argument
104 if (!stw || !fn) { in iwstw_schedule()
114 int rci = pthread_mutex_lock(&stw->mtx); in iwstw_schedule()
119 if (stw->shutdown) { in iwstw_schedule()
121 pthread_mutex_unlock(&stw->mtx); in iwstw_schedule()
124 if (stw->queue_limit && stw->cnt + 1 > stw->queue_limit) { in iwstw_schedule()
126 pthread_mutex_unlock(&stw->mtx); in iwstw_schedule()
129 if (stw->tail) { in iwstw_schedule()
130 stw->tail->next = task; in iwstw_schedule()
131 stw->tail = task; in iwstw_schedule()
133 stw->head = task; in iwstw_schedule()
134 stw->tail = task; in iwstw_schedule()
136 ++stw->cnt; in iwstw_schedule()
137 pthread_cond_broadcast(&stw->cond); in iwstw_schedule()
138 pthread_mutex_unlock(&stw->mtx); in iwstw_schedule()
148 struct _IWSTW *stw = malloc(sizeof(*stw)); in iwstw_start() local
149 if (!stw) { in iwstw_start()
155 *stw = (struct _IWSTW) { in iwstw_start()
160 rci = pthread_barrier_init(&stw->brr, 0, 2); in iwstw_start()
165 rci = pthread_create(&stw->thr, 0, worker_fn, stw); in iwstw_start()
168 pthread_barrier_destroy(&stw->brr); in iwstw_start()
171 pthread_barrier_wait(&stw->brr); in iwstw_start()
176 free(stw); in iwstw_start()
178 *stwp_out = stw; in iwstw_start()