libnx  v4.7.0
condvar.h
Go to the documentation of this file.
1 /**
2  * @file condvar.h
3  * @brief Condition variable synchronization primitive.
4  * @author plutoo
5  * @copyright libnx Authors
6  */
7 #pragma once
8 #include "../types.h"
9 #include "../kernel/svc.h"
10 #include "../kernel/mutex.h"
11 
12 /// Condition variable.
13 typedef u32 CondVar;
14 
15 /**
16  * @brief Initializes a condition variable.
17  * @param[in] c Condition variable object.
18  */
19 static inline void condvarInit(CondVar* c)
20 {
21  *c = 0;
22 }
23 
24 /**
25  * @brief Waits on a condition variable with a timeout.
26  * @param[in] c Condition variable object.
27  * @param[in] m Mutex object to use inside the condition variable.
28  * @param[in] timeout Timeout in nanoseconds.
29  * @return Result code (0xEA01 on timeout).
30  * @remark On function return, the underlying mutex is acquired.
31  */
33 
34 /**
35  * @brief Waits on a condition variable.
36  * @param[in] c Condition variable object.
37  * @param[in] m Mutex object to use inside the condition variable.
38  * @return Result code.
39  * @remark On function return, the underlying mutex is acquired.
40  */
41 static inline Result condvarWait(CondVar* c, Mutex* m)
42 {
43  return condvarWaitTimeout(c, m, UINT64_MAX);
44 }
45 
46 /**
47  * @brief Wakes up up to the specified number of threads waiting on a condition variable.
48  * @param[in] c Condition variable object.
49  * @param[in] num Maximum number of threads to wake up (or -1 to wake them all up).
50  * @return Result code.
51  */
52 static inline Result condvarWake(CondVar* c, int num)
53 {
55  return 0;
56 }
57 
58 /**
59  * @brief Wakes up a single thread waiting on a condition variable.
60  * @param[in] c Condition variable object.
61  * @return Result code.
62  */
63 static inline Result condvarWakeOne(CondVar* c)
64 {
65  return condvarWake(c, 1);
66 }
67 
68 /**
69  * @brief Wakes up all thread waiting on a condition variable.
70  * @param[in] c Condition variable object.
71  * @return Result code.
72  */
73 static inline Result condvarWakeAll(CondVar* c)
74 {
75  return condvarWake(c, -1);
76 }
Result condvarWaitTimeout(CondVar *c, Mutex *m, u64 timeout)
Waits on a condition variable with a timeout.
static Result condvarWakeAll(CondVar *c)
Wakes up all thread waiting on a condition variable.
Definition: condvar.h:73
static Result condvarWake(CondVar *c, int num)
Wakes up up to the specified number of threads waiting on a condition variable.
Definition: condvar.h:52
static void condvarInit(CondVar *c)
Initializes a condition variable.
Definition: condvar.h:19
static Result condvarWait(CondVar *c, Mutex *m)
Waits on a condition variable.
Definition: condvar.h:41
u32 CondVar
Condition variable.
Definition: condvar.h:13
static Result condvarWakeOne(CondVar *c)
Wakes up a single thread waiting on a condition variable.
Definition: condvar.h:63
_LOCK_T Mutex
Mutex datatype, defined in newlib.
Definition: mutex.h:12
void svcSignalProcessWideKey(u32 *key, s32 num)
Performs a condition variable wake-up operation in userspace.
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
u32 Result
Function error code result type.
Definition: types.h:44
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21