Lines Matching +full:wake +full:- +full:up
45 * running and wakes up the zthr.
46 * 2] The zthr wakes up, checks the indicator and starts working.
55 * ensure that they fit your use-case well before using them.
61 * 1] A user-defined checker function (checkfunc) that decides whether
67 * 2] A user-defined ZTHR function (func) which the zthr executes when
91 * NOTE: ZTHR threads could potentially wake up spuriously and the
108 * signal every time func returns and every time it wakes up [see
112 * time. This may be very time-consuming for some operations that
129 * Cancelling a zthr doesn't clean up its metadata (internal locks,
142 * | woke up
143 * | +--------------+ sleep
149 * cancelled? +---------> checkfunc?
155 * | +---------------+ func
196 * if this is 0, the thread doesn't wake up until it gets
201 /* consumer-provided callbacks & data */
212 mutex_enter(&t->zthr_state_lock); in zthr_procedure()
213 ASSERT3P(t->zthr_thread, ==, curthread); in zthr_procedure()
215 while (!t->zthr_cancel) { in zthr_procedure()
216 if (t->zthr_checkfunc(t->zthr_arg, t)) { in zthr_procedure()
217 mutex_exit(&t->zthr_state_lock); in zthr_procedure()
218 t->zthr_func(t->zthr_arg, t); in zthr_procedure()
219 mutex_enter(&t->zthr_state_lock); in zthr_procedure()
222 if (t->zthr_wait_time == 0) { in zthr_procedure()
223 cv_wait(&t->zthr_cv, &t->zthr_state_lock); in zthr_procedure()
225 (void) cv_timedwait_hires(&t->zthr_cv, in zthr_procedure()
226 &t->zthr_state_lock, t->zthr_wait_time, in zthr_procedure()
236 t->zthr_thread = NULL; in zthr_procedure()
237 t->zthr_cancel = B_FALSE; in zthr_procedure()
238 cv_broadcast(&t->zthr_cv); in zthr_procedure()
240 mutex_exit(&t->zthr_state_lock); in zthr_procedure()
260 mutex_init(&t->zthr_state_lock, NULL, MUTEX_DEFAULT, NULL); in zthr_create_timer()
261 mutex_init(&t->zthr_request_lock, NULL, MUTEX_DEFAULT, NULL); in zthr_create_timer()
262 cv_init(&t->zthr_cv, NULL, CV_DEFAULT, NULL); in zthr_create_timer()
264 mutex_enter(&t->zthr_state_lock); in zthr_create_timer()
265 t->zthr_checkfunc = checkfunc; in zthr_create_timer()
266 t->zthr_func = func; in zthr_create_timer()
267 t->zthr_arg = arg; in zthr_create_timer()
268 t->zthr_wait_time = max_sleep; in zthr_create_timer()
270 t->zthr_thread = thread_create(NULL, 0, zthr_procedure, t, in zthr_create_timer()
272 mutex_exit(&t->zthr_state_lock); in zthr_create_timer()
280 ASSERT(!MUTEX_HELD(&t->zthr_state_lock)); in zthr_destroy()
281 ASSERT(!MUTEX_HELD(&t->zthr_request_lock)); in zthr_destroy()
282 VERIFY3P(t->zthr_thread, ==, NULL); in zthr_destroy()
283 mutex_destroy(&t->zthr_request_lock); in zthr_destroy()
284 mutex_destroy(&t->zthr_state_lock); in zthr_destroy()
285 cv_destroy(&t->zthr_cv); in zthr_destroy()
290 * Wake up the zthr if it is sleeping. If the thread has been
296 mutex_enter(&t->zthr_request_lock); in zthr_wakeup()
297 mutex_enter(&t->zthr_state_lock); in zthr_wakeup()
304 * point the broadcast will wake it up. in zthr_wakeup()
305 * [2] The thread has been cancelled. Waking up a cancelled in zthr_wakeup()
306 * thread is a no-op. Any work that is still left to be in zthr_wakeup()
309 * [3] The thread is doing work and is already up, so this in zthr_wakeup()
310 * is basically a no-op. in zthr_wakeup()
314 cv_broadcast(&t->zthr_cv); in zthr_wakeup()
316 mutex_exit(&t->zthr_state_lock); in zthr_wakeup()
317 mutex_exit(&t->zthr_request_lock); in zthr_wakeup()
323 * already), this is a no-op.
328 mutex_enter(&t->zthr_request_lock); in zthr_cancel()
329 mutex_enter(&t->zthr_state_lock); in zthr_cancel()
338 * to wake it up and then we set the flag and we are in zthr_cancel()
349 if (t->zthr_thread != NULL) { in zthr_cancel()
350 t->zthr_cancel = B_TRUE; in zthr_cancel()
353 cv_broadcast(&t->zthr_cv); in zthr_cancel()
355 while (t->zthr_thread != NULL) in zthr_cancel()
356 cv_wait(&t->zthr_cv, &t->zthr_state_lock); in zthr_cancel()
358 ASSERT(!t->zthr_cancel); in zthr_cancel()
361 mutex_exit(&t->zthr_state_lock); in zthr_cancel()
362 mutex_exit(&t->zthr_request_lock); in zthr_cancel()
367 * already running this is a no-op.
372 mutex_enter(&t->zthr_request_lock); in zthr_resume()
373 mutex_enter(&t->zthr_state_lock); in zthr_resume()
375 ASSERT3P(&t->zthr_checkfunc, !=, NULL); in zthr_resume()
376 ASSERT3P(&t->zthr_func, !=, NULL); in zthr_resume()
377 ASSERT(!t->zthr_cancel); in zthr_resume()
385 * [2] The zthr is running at which point this is a no-op. in zthr_resume()
386 * [3] The zthr is sleeping at which point this is a no-op. in zthr_resume()
388 * no-op. in zthr_resume()
390 if (t->zthr_thread == NULL) { in zthr_resume()
391 t->zthr_thread = thread_create(NULL, 0, zthr_procedure, t, in zthr_resume()
395 mutex_exit(&t->zthr_state_lock); in zthr_resume()
396 mutex_exit(&t->zthr_request_lock); in zthr_resume()
413 ASSERT3P(t->zthr_thread, ==, curthread); in zthr_iscancelled()
427 mutex_enter(&t->zthr_state_lock); in zthr_iscancelled()
428 boolean_t cancelled = t->zthr_cancel; in zthr_iscancelled()
429 mutex_exit(&t->zthr_state_lock); in zthr_iscancelled()