Lines Matching refs:thread
25 #include <isc/thread.h>
62 isc_work_cb cb; /* runs on a worker thread */
75 isc_thread_t thread;
96 workthread_wake(isc__workthread_t *thread) {
98 if ((uatomic_load(&thread->state, CMM_RELAXED) & THREAD_RUNNING) != 0) {
103 uatomic_or(&thread->state, THREAD_WAKEUP);
104 if (futex_noasync(&thread->state, FUTEX_WAKE, 1, NULL, NULL, 0) < 0) {
110 workthread_slumber(isc__workthread_t *thread) {
112 while (futex_noasync(&thread->state, FUTEX_WAIT, THREAD_WAITING, NULL,
127 workthread_sleep(isc__workthread_t *thread) {
132 uatomic_and(&thread->state, THREAD_STICKY);
140 if (cds_wfcq_empty(&thread->qhead, &thread->qtail)) {
141 workthread_slumber(thread);
145 uatomic_or(&thread->state, THREAD_RUNNING);
155 workthread_ack_pause(isc__workthread_t *thread) {
158 old = uatomic_load(&thread->state, CMM_RELAXED);
160 } while (uatomic_cmpxchg(&thread->state, old, next) != old);
162 (void)futex_noasync(&thread->state, FUTEX_WAKE, INT_MAX, NULL, NULL, 0);
173 workthread_pause(isc__workthread_t *thread) {
177 int32_t old = uatomic_load(&thread->state, CMM_ACQUIRE);
182 workthread_ack_pause(thread);
185 (void)futex_noasync(&thread->state, FUTEX_WAIT, old, NULL, NULL,
189 uatomic_and(&thread->state, ~THREAD_PAUSED);
236 isc__workthread_t *thread = arg;
238 isc__loopmgr_starting(thread->loop);
245 int32_t state = uatomic_load(&thread->state, CMM_ACQUIRE);
248 workthread_pause(thread);
253 node = __cds_wfcq_dequeue_blocking(&thread->qhead,
254 &thread->qtail);
260 if ((uatomic_load(&thread->state, CMM_ACQUIRE) &
264 if (!cds_wfcq_empty(&thread->qhead,
265 &thread->qtail))
272 workthread_sleep(thread);
281 isc__loopmgr_stopping(thread->loop);
291 isc__workthread_t *thread = isc__loopmgr_workthread(loop, lane);
305 if ((uatomic_load(&thread->state, CMM_ACQUIRE) & THREAD_SHUTDOWN) != 0)
317 (void)cds_wfcq_enqueue(&thread->qhead, &thread->qtail,
321 if ((uatomic_load(&thread->state, CMM_ACQUIRE) &
324 workthread_wake(thread);
348 isc__workthread_t *thread = isc_mem_get(loop->mctx, sizeof(*thread));
350 *thread = (isc__workthread_t){
357 __cds_wfcq_init(&thread->qhead, &thread->qtail);
359 isc_thread_create(workthread_thread, thread, &thread->thread);
361 return thread;
365 isc__workthread_shutdown(isc__workthread_t *thread) {
366 REQUIRE(VALID_WORKTHREAD(thread));
379 old = uatomic_load(&thread->state, CMM_RELAXED);
383 } while (uatomic_cmpxchg(&thread->state, old, old | THREAD_SHUTDOWN) !=
389 workthread_wake(thread);
395 isc__workthread_t *thread = MOVE_OWNERSHIP(*threadp);
397 isc_thread_join(thread->thread, NULL);
399 INSIST(cds_wfcq_empty(&thread->qhead, &thread->qtail));
401 thread->magic = 0;
402 isc_mem_put(thread->loop->mctx, thread, sizeof(*thread));
406 isc__workthread_pause(isc__workthread_t *thread) {
407 REQUIRE(VALID_WORKTHREAD(thread));
418 old = uatomic_load(&thread->state, CMM_RELAXED);
422 } while (uatomic_cmpxchg(&thread->state, old,
425 workthread_wake(thread);
432 old = uatomic_load(&thread->state, CMM_ACQUIRE);
436 (void)futex_noasync(&thread->state, FUTEX_WAIT, old, NULL, NULL,
442 isc__workthread_resume(isc__workthread_t *thread) {
443 REQUIRE(VALID_WORKTHREAD(thread));
446 uatomic_and(&thread->state, ~THREAD_PAUSE);
447 (void)futex_noasync(&thread->state, FUTEX_WAKE, INT_MAX, NULL, NULL, 0);