[f761f1eb] | 1 | /*
|
---|
[df4ed85] | 2 | * Copyright (c) 2001-2004 Jakub Jermar
|
---|
[0b47781] | 3 | * Copyright (c) 2025 Jiří Zárevúcky
|
---|
[f761f1eb] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
[e88eb48] | 30 | /** @addtogroup kernel_sync
|
---|
[b45c443] | 31 | * @{
|
---|
| 32 | */
|
---|
| 33 | /** @file
|
---|
| 34 | */
|
---|
| 35 |
|
---|
[06e1e95] | 36 | #ifndef KERN_CONDVAR_H_
|
---|
| 37 | #define KERN_CONDVAR_H_
|
---|
[f761f1eb] | 38 |
|
---|
[83dab11] | 39 | #include <stdint.h>
|
---|
[f761f1eb] | 40 | #include <synch/waitq.h>
|
---|
[e71a61d] | 41 | #include <synch/mutex.h>
|
---|
[46a5b37] | 42 | #include <synch/spinlock.h>
|
---|
[c0699467] | 43 | #include <abi/synch.h>
|
---|
[f761f1eb] | 44 |
|
---|
[e71a61d] | 45 | typedef struct {
|
---|
[f761f1eb] | 46 | waitq_t wq;
|
---|
[e71a61d] | 47 | } condvar_t;
|
---|
[f761f1eb] | 48 |
|
---|
[597fa24] | 49 | #define CONDVAR_INITIALIZER(name) (condvar_t) { \
|
---|
| 50 | .wq = WAITQ_INITIALIZER((name).wq), \
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | #define CONDVAR_INITIALIZE(name) \
|
---|
| 54 | condvar_t name = CONDVAR_INITIALIZER(name)
|
---|
| 55 |
|
---|
[f761f1eb] | 56 | extern void condvar_initialize(condvar_t *cv);
|
---|
| 57 | extern void condvar_signal(condvar_t *cv);
|
---|
| 58 | extern void condvar_broadcast(condvar_t *cv);
|
---|
[5110d0a] | 59 |
|
---|
[0b47781] | 60 | extern errno_t __condvar_wait_mutex(condvar_t *cv, mutex_t *mtx);
|
---|
| 61 | extern errno_t __condvar_wait_spinlock(condvar_t *cv, spinlock_t *mtx);
|
---|
| 62 | extern errno_t __condvar_wait_irq_spinlock(condvar_t *cv, irq_spinlock_t *mtx);
|
---|
| 63 | extern errno_t __condvar_wait_timeout_mutex(condvar_t *cv, mutex_t *mtx, uint32_t usec);
|
---|
| 64 | extern errno_t __condvar_wait_timeout_spinlock(condvar_t *cv, spinlock_t *mtx, uint32_t usec);
|
---|
| 65 | extern errno_t __condvar_wait_timeout_irq_spinlock(condvar_t *cv, irq_spinlock_t *mtx, uint32_t usec);
|
---|
| 66 |
|
---|
| 67 | #define condvar_wait(cv, mtx) (_Generic((mtx), \
|
---|
| 68 | mutex_t *: __condvar_wait_mutex, \
|
---|
| 69 | spinlock_t *: __condvar_wait_spinlock, \
|
---|
| 70 | irq_spinlock_t *: __condvar_wait_irq_spinlock \
|
---|
| 71 | )(cv, mtx))
|
---|
[5110d0a] | 72 |
|
---|
[0b47781] | 73 | #define condvar_wait_timeout(cv, mtx, usec) (_Generic((mtx), \
|
---|
| 74 | mutex_t *: __condvar_wait_timeout_mutex, \
|
---|
| 75 | spinlock_t *: __condvar_wait_timeout_spinlock, \
|
---|
| 76 | irq_spinlock_t *: __condvar_wait_timeout_irq_spinlock \
|
---|
| 77 | )(cv, mtx))
|
---|
[46a5b37] | 78 |
|
---|
[f761f1eb] | 79 | #endif
|
---|
[b45c443] | 80 |
|
---|
[06e1e95] | 81 | /** @}
|
---|
[b45c443] | 82 | */
|
---|