source: mainline/kernel/generic/src/synch/waitq.c@ e29e44bf

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since e29e44bf was 9fe9d296, checked in by Adam Hraska <adam.hraska+hos@…>, 13 years ago

Fix: waitq_sleep_timeout() waits for its waitq_wakeup() to complete unconditionally. No need to wait explicitly via waitq_complete_wakeup() anymore.

  • Property mode set to 100644
File size: 16.5 KB
RevLine 
[f761f1eb]1/*
[df4ed85]2 * Copyright (c) 2001-2004 Jakub Jermar
[f761f1eb]3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
[cc73a8a1]29/** @addtogroup sync
[b45c443]30 * @{
31 */
32
[9179d0a]33/**
[b45c443]34 * @file
[da1bafb]35 * @brief Wait queue.
[9179d0a]36 *
[e3c762cd]37 * Wait queue is the basic synchronization primitive upon which all
[9179d0a]38 * other synchronization primitives build.
39 *
40 * It allows threads to wait for an event in first-come, first-served
41 * fashion. Conditional operation as well as timeouts and interruptions
42 * are supported.
[da1bafb]43 *
[9179d0a]44 */
45
[f761f1eb]46#include <synch/waitq.h>
47#include <synch/spinlock.h>
[922c7ce]48#include <proc/thread.h>
[4b2c872d]49#include <proc/scheduler.h>
[f761f1eb]50#include <arch/asm.h>
[d99c1d2]51#include <typedefs.h>
[922c7ce]52#include <time/timeout.h>
[f761f1eb]53#include <arch.h>
[922c7ce]54#include <context.h>
[5c9a08b]55#include <adt/list.h>
[6ec34bb]56#include <arch/cycle.h>
[f761f1eb]57
[da1bafb]58static void waitq_sleep_timed_out(void *);
[9fe9d296]59static void waitq_complete_wakeup(waitq_t *);
60
[203f4c3]61
[922c7ce]62/** Initialize wait queue
63 *
64 * Initialize wait queue.
65 *
[da1bafb]66 * @param wq Pointer to wait queue to be initialized.
67 *
[922c7ce]68 */
[f761f1eb]69void waitq_initialize(waitq_t *wq)
70{
[da1bafb]71 irq_spinlock_initialize(&wq->lock, "wq.lock");
[55b77d9]72 list_initialize(&wq->sleepers);
[f761f1eb]73 wq->missed_wakeups = 0;
74}
75
[922c7ce]76/** Handle timeout during waitq_sleep_timeout() call
77 *
[ace9358]78 * This routine is called when waitq_sleep_timeout() times out.
[922c7ce]79 * Interrupts are disabled.
[f761f1eb]80 *
[922c7ce]81 * It is supposed to try to remove 'its' thread from the wait queue;
82 * it can eventually fail to achieve this goal when these two events
83 * overlap. In that case it behaves just as though there was no
84 * timeout at all.
85 *
[da1bafb]86 * @param data Pointer to the thread that called waitq_sleep_timeout().
87 *
[f761f1eb]88 */
[929ce92]89void waitq_sleep_timed_out(void *data)
[f761f1eb]90{
[da1bafb]91 thread_t *thread = (thread_t *) data;
[05e2a7ad]92 bool do_wakeup = false;
[31d8e10]93 DEADLOCK_PROBE_INIT(p_wqlock);
[da1bafb]94
95 irq_spinlock_lock(&threads_lock, false);
96 if (!thread_exists(thread))
[f761f1eb]97 goto out;
[da1bafb]98
[f761f1eb]99grab_locks:
[da1bafb]100 irq_spinlock_lock(&thread->lock, false);
101
102 waitq_t *wq;
103 if ((wq = thread->sleep_queue)) { /* Assignment */
104 if (!irq_spinlock_trylock(&wq->lock)) {
105 irq_spinlock_unlock(&thread->lock, false);
[31d8e10]106 DEADLOCK_PROBE(p_wqlock, DEADLOCK_THRESHOLD);
[da1bafb]107 /* Avoid deadlock */
108 goto grab_locks;
[f761f1eb]109 }
[da1bafb]110
111 list_remove(&thread->wq_link);
112 thread->saved_context = thread->sleep_timeout_context;
[05e2a7ad]113 do_wakeup = true;
[da1bafb]114 thread->sleep_queue = NULL;
115 irq_spinlock_unlock(&wq->lock, false);
[f761f1eb]116 }
117
[da1bafb]118 thread->timeout_pending = false;
119 irq_spinlock_unlock(&thread->lock, false);
[f761f1eb]120
[05e2a7ad]121 if (do_wakeup)
[da1bafb]122 thread_ready(thread);
123
[f761f1eb]124out:
[da1bafb]125 irq_spinlock_unlock(&threads_lock, false);
[f761f1eb]126}
127
[5573942]128/** Interrupt sleeping thread.
129 *
[df58e44]130 * This routine attempts to interrupt a thread from its sleep in
131 * a waitqueue. If the thread is not found sleeping, no action
132 * is taken.
133 *
134 * The threads_lock must be already held and interrupts must be
135 * disabled upon calling this function.
[5573942]136 *
[da1bafb]137 * @param thread Thread to be interrupted.
138 *
[5573942]139 */
[da1bafb]140void waitq_interrupt_sleep(thread_t *thread)
[5573942]141{
142 bool do_wakeup = false;
[31d8e10]143 DEADLOCK_PROBE_INIT(p_wqlock);
[da1bafb]144
[df58e44]145 /*
146 * The thread is quaranteed to exist because
147 * threads_lock is held.
148 */
[da1bafb]149
[5573942]150grab_locks:
[da1bafb]151 irq_spinlock_lock(&thread->lock, false);
152
153 waitq_t *wq;
154 if ((wq = thread->sleep_queue)) { /* Assignment */
155 if (!(thread->sleep_interruptible)) {
[5573942]156 /*
157 * The sleep cannot be interrupted.
158 */
[da1bafb]159 irq_spinlock_unlock(&thread->lock, false);
[df58e44]160 return;
[5573942]161 }
[da1bafb]162
163 if (!irq_spinlock_trylock(&wq->lock)) {
[df58e44]164 /* Avoid deadlock */
[da1bafb]165 irq_spinlock_unlock(&thread->lock, false);
[31d8e10]166 DEADLOCK_PROBE(p_wqlock, DEADLOCK_THRESHOLD);
[da1bafb]167 goto grab_locks;
[5573942]168 }
[da1bafb]169
170 if ((thread->timeout_pending) &&
171 (timeout_unregister(&thread->sleep_timeout)))
172 thread->timeout_pending = false;
173
174 list_remove(&thread->wq_link);
175 thread->saved_context = thread->sleep_interruption_context;
[5573942]176 do_wakeup = true;
[da1bafb]177 thread->sleep_queue = NULL;
178 irq_spinlock_unlock(&wq->lock, false);
[5573942]179 }
[df58e44]180
[da1bafb]181 irq_spinlock_unlock(&thread->lock, false);
182
[5573942]183 if (do_wakeup)
[da1bafb]184 thread_ready(thread);
[5573942]185}
[203f4c3]186
[6c4a56f]187/** Interrupt the first thread sleeping in the wait queue.
188 *
189 * Note that the caller somehow needs to know that the thread to be interrupted
190 * is sleeping interruptibly.
191 *
[da1bafb]192 * @param wq Pointer to wait queue.
193 *
[6c4a56f]194 */
195void waitq_unsleep(waitq_t *wq)
196{
[da1bafb]197 irq_spinlock_lock(&wq->lock, true);
198
[55b77d9]199 if (!list_empty(&wq->sleepers)) {
200 thread_t *thread = list_get_instance(list_first(&wq->sleepers),
201 thread_t, wq_link);
[6c4a56f]202
[da1bafb]203 irq_spinlock_lock(&thread->lock, false);
204
205 ASSERT(thread->sleep_interruptible);
206
207 if ((thread->timeout_pending) &&
208 (timeout_unregister(&thread->sleep_timeout)))
209 thread->timeout_pending = false;
210
211 list_remove(&thread->wq_link);
212 thread->saved_context = thread->sleep_interruption_context;
213 thread->sleep_queue = NULL;
214
215 irq_spinlock_unlock(&thread->lock, false);
216 thread_ready(thread);
[6c4a56f]217 }
[da1bafb]218
219 irq_spinlock_unlock(&wq->lock, true);
[6c4a56f]220}
221
[4039c77]222#define PARAM_NON_BLOCKING(flags, usec) \
223 (((flags) & SYNCH_FLAGS_NON_BLOCKING) && ((usec) == 0))
224
[203f4c3]225/** Sleep until either wakeup, timeout or interruption occurs
[922c7ce]226 *
[116d1ef4]227 * This is a sleep implementation which allows itself to time out or to be
[f761f1eb]228 * interrupted from the sleep, restoring a failover context.
229 *
[c0bc189]230 * Sleepers are organised in a FIFO fashion in a structure called wait queue.
[922c7ce]231 *
[f761f1eb]232 * This function is really basic in that other functions as waitq_sleep()
233 * and all the *_timeout() functions use it.
234 *
[da1bafb]235 * @param wq Pointer to wait queue.
236 * @param usec Timeout in microseconds.
237 * @param flags Specify mode of the sleep.
[922c7ce]238 *
[116d1ef4]239 * The sleep can be interrupted only if the
240 * SYNCH_FLAGS_INTERRUPTIBLE bit is specified in flags.
[da1bafb]241 *
[116d1ef4]242 * If usec is greater than zero, regardless of the value of the
[4e33b6b]243 * SYNCH_FLAGS_NON_BLOCKING bit in flags, the call will not return until either
[da1bafb]244 * timeout, interruption or wakeup comes.
[f761f1eb]245 *
[4e33b6b]246 * If usec is zero and the SYNCH_FLAGS_NON_BLOCKING bit is not set in flags,
247 * the call will not return until wakeup or interruption comes.
[a783ca4]248 *
[4e33b6b]249 * If usec is zero and the SYNCH_FLAGS_NON_BLOCKING bit is set in flags, the
250 * call will immediately return, reporting either success or failure.
[f761f1eb]251 *
[da1bafb]252 * @return ESYNCH_WOULD_BLOCK, meaning that the sleep failed because at the
253 * time of the call there was no pending wakeup
254 * @return ESYNCH_TIMEOUT, meaning that the sleep timed out.
255 * @return ESYNCH_INTERRUPTED, meaning that somebody interrupted the sleeping
256 * thread.
257 * @return ESYNCH_OK_ATOMIC, meaning that the sleep succeeded and that there
258 * was a pending wakeup at the time of the call. The caller was not put
259 * asleep at all.
260 * @return ESYNCH_OK_BLOCKED, meaning that the sleep succeeded; the full sleep
261 * was attempted.
[922c7ce]262 *
[f761f1eb]263 */
[da1bafb]264int waitq_sleep_timeout(waitq_t *wq, uint32_t usec, unsigned int flags)
[f761f1eb]265{
[2e4e706]266 ASSERT((!PREEMPTION_DISABLED) || (PARAM_NON_BLOCKING(flags, usec)));
[f761f1eb]267
[da1bafb]268 ipl_t ipl = waitq_sleep_prepare(wq);
269 int rc = waitq_sleep_timeout_unsafe(wq, usec, flags);
[c0bc189]270 waitq_sleep_finish(wq, rc, ipl);
271 return rc;
272}
273
274/** Prepare to sleep in a waitq.
275 *
276 * This function will return holding the lock of the wait queue
277 * and interrupts disabled.
278 *
[da1bafb]279 * @param wq Wait queue.
280 *
281 * @return Interrupt level as it existed on entry to this function.
[c0bc189]282 *
283 */
284ipl_t waitq_sleep_prepare(waitq_t *wq)
285{
286 ipl_t ipl;
[f761f1eb]287
288restart:
[22f7769]289 ipl = interrupts_disable();
[da1bafb]290
291 if (THREAD) { /* Needed during system initiailzation */
[343fc179]292 /*
293 * Busy waiting for a delayed timeout.
294 * This is an important fix for the race condition between
295 * a delayed timeout and a next call to waitq_sleep_timeout().
296 * Simply, the thread is not allowed to go to sleep if
297 * there are timeouts in progress.
[da1bafb]298 *
[343fc179]299 */
[da1bafb]300 irq_spinlock_lock(&THREAD->lock, false);
301
[343fc179]302 if (THREAD->timeout_pending) {
[da1bafb]303 irq_spinlock_unlock(&THREAD->lock, false);
[343fc179]304 interrupts_restore(ipl);
305 goto restart;
306 }
[da1bafb]307
308 irq_spinlock_unlock(&THREAD->lock, false);
[f761f1eb]309 }
[da1bafb]310
311 irq_spinlock_lock(&wq->lock, false);
[c0bc189]312 return ipl;
313}
314
315/** Finish waiting in a wait queue.
316 *
317 * This function restores interrupts to the state that existed prior
318 * to the call to waitq_sleep_prepare(). If necessary, the wait queue
319 * lock is released.
320 *
[da1bafb]321 * @param wq Wait queue.
322 * @param rc Return code of waitq_sleep_timeout_unsafe().
323 * @param ipl Interrupt level returned by waitq_sleep_prepare().
324 *
[c0bc189]325 */
326void waitq_sleep_finish(waitq_t *wq, int rc, ipl_t ipl)
327{
328 switch (rc) {
329 case ESYNCH_WOULD_BLOCK:
330 case ESYNCH_OK_ATOMIC:
[da1bafb]331 irq_spinlock_unlock(&wq->lock, false);
[c0bc189]332 break;
333 default:
[9fe9d296]334 /*
335 * Wait for a waitq_wakeup() or waitq_unsleep() to complete
336 * before returning from waitq_sleep() to the caller. Otherwise
337 * the caller might expect that the wait queue is no longer used
338 * and deallocate it (although the wakeup on a another cpu has
339 * not yet completed and is using the wait queue).
340 *
341 * Note that we have to do this for ESYNCH_OK_BLOCKED and
342 * ESYNCH_INTERRUPTED, but not necessarily for ESYNCH_TIMEOUT
343 * where the timeout handler stops using the waitq before waking
344 * us up. To be on the safe side, ensure the waitq is not in use
345 * anymore in this case as well.
346 */
347 waitq_complete_wakeup(wq);
[c0bc189]348 break;
349 }
[da1bafb]350
[c0bc189]351 interrupts_restore(ipl);
352}
353
354/** Internal implementation of waitq_sleep_timeout().
355 *
356 * This function implements logic of sleeping in a wait queue.
[ace9358]357 * This call must be preceded by a call to waitq_sleep_prepare()
358 * and followed by a call to waitq_sleep_finish().
[c0bc189]359 *
[da1bafb]360 * @param wq See waitq_sleep_timeout().
361 * @param usec See waitq_sleep_timeout().
362 * @param flags See waitq_sleep_timeout().
363 *
364 * @return See waitq_sleep_timeout().
[c0bc189]365 *
366 */
[da1bafb]367int waitq_sleep_timeout_unsafe(waitq_t *wq, uint32_t usec, unsigned int flags)
[c0bc189]368{
[da1bafb]369 /* Checks whether to go to sleep at all */
[f761f1eb]370 if (wq->missed_wakeups) {
371 wq->missed_wakeups--;
372 return ESYNCH_OK_ATOMIC;
[da1bafb]373 } else {
[4039c77]374 if (PARAM_NON_BLOCKING(flags, usec)) {
[9fe9d296]375 /* Return immediately instead of going to sleep */
[f761f1eb]376 return ESYNCH_WOULD_BLOCK;
377 }
378 }
379
380 /*
381 * Now we are firmly decided to go to sleep.
[da1bafb]382 *
[f761f1eb]383 */
[da1bafb]384 irq_spinlock_lock(&THREAD->lock, false);
385
[116d1ef4]386 if (flags & SYNCH_FLAGS_INTERRUPTIBLE) {
[34dcd3f]387 /*
388 * If the thread was already interrupted,
389 * don't go to sleep at all.
390 */
391 if (THREAD->interrupted) {
[da1bafb]392 irq_spinlock_unlock(&THREAD->lock, false);
393 irq_spinlock_unlock(&wq->lock, false);
[34dcd3f]394 return ESYNCH_INTERRUPTED;
395 }
[da1bafb]396
[116d1ef4]397 /*
398 * Set context that will be restored if the sleep
399 * of this thread is ever interrupted.
400 */
401 THREAD->sleep_interruptible = true;
402 if (!context_save(&THREAD->sleep_interruption_context)) {
403 /* Short emulation of scheduler() return code. */
[6ec34bb]404 THREAD->last_cycle = get_cycle();
[da1bafb]405 irq_spinlock_unlock(&THREAD->lock, false);
[116d1ef4]406 return ESYNCH_INTERRUPTED;
407 }
[da1bafb]408 } else
[116d1ef4]409 THREAD->sleep_interruptible = false;
[da1bafb]410
[f761f1eb]411 if (usec) {
412 /* We use the timeout variant. */
[43114c5]413 if (!context_save(&THREAD->sleep_timeout_context)) {
[203f4c3]414 /* Short emulation of scheduler() return code. */
[6ec34bb]415 THREAD->last_cycle = get_cycle();
[da1bafb]416 irq_spinlock_unlock(&THREAD->lock, false);
[f761f1eb]417 return ESYNCH_TIMEOUT;
418 }
[da1bafb]419
[05e2a7ad]420 THREAD->timeout_pending = true;
[4e33b6b]421 timeout_register(&THREAD->sleep_timeout, (uint64_t) usec,
[929ce92]422 waitq_sleep_timed_out, THREAD);
[f761f1eb]423 }
[da1bafb]424
[55b77d9]425 list_append(&THREAD->wq_link, &wq->sleepers);
[da1bafb]426
[f761f1eb]427 /*
428 * Suspend execution.
[da1bafb]429 *
[f761f1eb]430 */
[43114c5]431 THREAD->state = Sleeping;
432 THREAD->sleep_queue = wq;
[da1bafb]433
434 irq_spinlock_unlock(&THREAD->lock, false);
435
[4e33b6b]436 /* wq->lock is released in scheduler_separated_stack() */
[da1bafb]437 scheduler();
[f761f1eb]438
439 return ESYNCH_OK_BLOCKED;
440}
441
[922c7ce]442/** Wake up first thread sleeping in a wait queue
443 *
[4e33b6b]444 * Wake up first thread sleeping in a wait queue. This is the SMP- and IRQ-safe
445 * wrapper meant for general use.
[922c7ce]446 *
[4e33b6b]447 * Besides its 'normal' wakeup operation, it attempts to unregister possible
448 * timeout.
[922c7ce]449 *
[da1bafb]450 * @param wq Pointer to wait queue.
451 * @param mode Wakeup mode.
452 *
[f761f1eb]453 */
[5c8ba05]454void waitq_wakeup(waitq_t *wq, wakeup_mode_t mode)
[f761f1eb]455{
[da1bafb]456 irq_spinlock_lock(&wq->lock, true);
[5c8ba05]457 _waitq_wakeup_unsafe(wq, mode);
[da1bafb]458 irq_spinlock_unlock(&wq->lock, true);
[f761f1eb]459}
460
[3954961e]461/** If there is a wakeup in progress actively waits for it to complete.
462 *
463 * The function returns once the concurrently running waitq_wakeup()
464 * exits. It returns immediately if there are no concurrent wakeups
465 * at the time.
466 *
[9fe9d296]467 * Interrupts must be disabled.
468 *
[3954961e]469 * Example usage:
470 * @code
471 * void callback(waitq *wq)
472 * {
473 * // Do something and notify wait_for_completion() that we're done.
474 * waitq_wakeup(wq);
475 * }
476 * void wait_for_completion(void)
477 * {
478 * waitq wg;
479 * waitq_initialize(&wq);
480 * // Run callback() in the background, pass it wq.
481 * do_asynchronously(callback, &wq);
482 * // Wait for callback() to complete its work.
483 * waitq_sleep(&wq);
484 * // callback() completed its work, but it may still be accessing
485 * // wq in waitq_wakeup(). Therefore it is not yet safe to return
[9fe9d296]486 * // from waitq_sleep() or it would clobber up our stack (where wq
487 * // is stored). waitq_sleep() ensures the wait queue is no longer
488 * // in use by invoking waitq_complete_wakeup() internally.
489 *
490 * // waitq_sleep() returned, it is safe to free wq.
[3954961e]491 * }
492 * @endcode
493 *
494 * @param wq Pointer to a wait queue.
495 */
[9fe9d296]496static void waitq_complete_wakeup(waitq_t *wq)
[3954961e]497{
[9fe9d296]498 ASSERT(interrupts_disabled());
499
500 irq_spinlock_lock(&wq->lock, false);
501 irq_spinlock_unlock(&wq->lock, false);
[3954961e]502}
503
504
[922c7ce]505/** Internal SMP- and IRQ-unsafe version of waitq_wakeup()
506 *
[4e33b6b]507 * This is the internal SMP- and IRQ-unsafe version of waitq_wakeup(). It
508 * assumes wq->lock is already locked and interrupts are already disabled.
[922c7ce]509 *
[da1bafb]510 * @param wq Pointer to wait queue.
511 * @param mode If mode is WAKEUP_FIRST, then the longest waiting
512 * thread, if any, is woken up. If mode is WAKEUP_ALL, then
513 * all waiting threads, if any, are woken up. If there are
514 * no waiting threads to be woken up, the missed wakeup is
515 * recorded in the wait queue.
516 *
[f761f1eb]517 */
[5c8ba05]518void _waitq_wakeup_unsafe(waitq_t *wq, wakeup_mode_t mode)
[f761f1eb]519{
[98000fb]520 size_t count = 0;
[1d432f9]521
522 ASSERT(interrupts_disabled());
523 ASSERT(irq_spinlock_locked(&wq->lock));
[da1bafb]524
525loop:
[55b77d9]526 if (list_empty(&wq->sleepers)) {
[f761f1eb]527 wq->missed_wakeups++;
[da1bafb]528 if ((count) && (mode == WAKEUP_ALL))
[5c8ba05]529 wq->missed_wakeups--;
[da1bafb]530
[f761f1eb]531 return;
532 }
[da1bafb]533
[5c8ba05]534 count++;
[55b77d9]535 thread_t *thread = list_get_instance(list_first(&wq->sleepers),
536 thread_t, wq_link);
[f761f1eb]537
[4b74488]538 /*
539 * Lock the thread prior to removing it from the wq.
540 * This is not necessary because of mutual exclusion
541 * (the link belongs to the wait queue), but because
[929ce92]542 * of synchronization with waitq_sleep_timed_out()
[b3f8fb7]543 * and thread_interrupt_sleep().
[4b74488]544 *
545 * In order for these two functions to work, the following
546 * invariant must hold:
547 *
[da1bafb]548 * thread->sleep_queue != NULL <=> thread sleeps in a wait queue
[4b74488]549 *
550 * For an observer who locks the thread, the invariant
551 * holds only when the lock is held prior to removing
552 * it from the wait queue.
[da1bafb]553 *
[4b74488]554 */
[da1bafb]555 irq_spinlock_lock(&thread->lock, false);
556 list_remove(&thread->wq_link);
557
558 if ((thread->timeout_pending) &&
559 (timeout_unregister(&thread->sleep_timeout)))
560 thread->timeout_pending = false;
561
562 thread->sleep_queue = NULL;
563 irq_spinlock_unlock(&thread->lock, false);
564
565 thread_ready(thread);
[4b74488]566
[5c8ba05]567 if (mode == WAKEUP_ALL)
[05e2a7ad]568 goto loop;
[f761f1eb]569}
[b45c443]570
[b7398c0]571/** Get the missed wakeups count.
572 *
573 * @param wq Pointer to wait queue.
574 * @return The wait queue's missed_wakeups count.
575 */
576int waitq_count_get(waitq_t *wq)
577{
578 int cnt;
579
580 irq_spinlock_lock(&wq->lock, true);
581 cnt = wq->missed_wakeups;
582 irq_spinlock_unlock(&wq->lock, true);
583
584 return cnt;
585}
586
587/** Set the missed wakeups count.
588 *
589 * @param wq Pointer to wait queue.
590 * @param val New value of the missed_wakeups count.
591 */
592void waitq_count_set(waitq_t *wq, int val)
593{
594 irq_spinlock_lock(&wq->lock, true);
595 wq->missed_wakeups = val;
596 irq_spinlock_unlock(&wq->lock, true);
597}
598
[cc73a8a1]599/** @}
[b45c443]600 */
Note: See TracBrowser for help on using the repository browser.