libnx  v4.2.2
levent.h
Go to the documentation of this file.
1 /**
2  * @file levent.h
3  * @brief Light event synchronization primitive [4.0.0+]
4  * @author fincs
5  * @copyright libnx Authors
6  */
7 #pragma once
8 #include "../types.h"
9 #include "../result.h"
10 #include "svc.h"
11 
12 /// User-mode light event structure.
13 typedef struct LEvent {
14  u32 counter;
15  bool autoclear;
16 } LEvent;
17 
18 /**
19  * @brief Initializes a user-mode light event.
20  * @param[out] le Pointer to \ref LEvent structure.
21  * @param[in] signaled Whether the event starts off in signaled state.
22  * @param[in] autoclear Autoclear flag.
23  */
24 NX_CONSTEXPR void leventInit(LEvent* le, bool signaled, bool autoclear) {
25  le->counter = signaled ? 2 : 0;
26  le->autoclear = autoclear;
27 }
28 
29 /**
30  * @brief Waits on a user-mode light event.
31  * @param[in] le Pointer to \ref LEvent structure.
32  * @param[in] timeout_ns Timeout in nanoseconds (pass UINT64_MAX to wait indefinitely).
33  * @return true if wait succeeded, false if wait timed out.
34  */
35 bool leventWait(LEvent* le, u64 timeout_ns);
36 
37 /**
38  * @brief Polls a user-mode light event.
39  * @param[in] le Pointer to \ref LEvent structure.
40  * @return true if event is signaled, false otherwise.
41  */
42 bool leventTryWait(LEvent* le);
43 
44 /**
45  * @brief Signals a user-mode light event.
46  * @param[in] le Pointer to \ref LEvent structure.
47  */
48 void leventSignal(LEvent* le);
49 
50 /**
51  * @brief Clears a user-mode light event.
52  * @param[in] le Pointer to \ref LEvent structure.
53  */
54 void leventClear(LEvent* le);
leventSignal
void leventSignal(LEvent *le)
Signals a user-mode light event.
leventWait
bool leventWait(LEvent *le, u64 timeout_ns)
Waits on a user-mode light event.
NX_CONSTEXPR
#define NX_CONSTEXPR
Flags a function as constexpr in C++14 and above; or as (always) inline otherwise.
Definition: types.h:92
u32
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21
u64
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
svc.h
Wrappers for kernel syscalls.
leventInit
static void leventInit(LEvent *le, bool signaled, bool autoclear)
Initializes a user-mode light event.
Definition: levent.h:24
leventClear
void leventClear(LEvent *le)
Clears a user-mode light event.
leventTryWait
bool leventTryWait(LEvent *le)
Polls a user-mode light event.
LEvent
User-mode light event structure.
Definition: levent.h:13