a3c46b7f |
1 | |
2 | #ifndef _3DS_SEMAPHORE_WRAP__ |
3 | #define _3DS_SEMAPHORE_WRAP__ |
4 | |
5 | #include <stdlib.h> |
6 | #include <string.h> |
7 | #include <stdio.h> |
8 | |
9 | #include "3ds_utils.h" |
10 | |
11 | typedef uint32_t sem_t; |
12 | |
13 | static inline int sem_init(sem_t *sem, int pshared, unsigned int value) |
14 | { |
15 | return svcCreateSemaphore(sem, value, INT32_MAX); |
16 | } |
17 | |
18 | static inline int sem_post(sem_t *sem) |
19 | { |
20 | int32_t count; |
21 | return svcReleaseSemaphore(&count, *sem, 1); |
22 | } |
23 | |
24 | static inline int sem_wait(sem_t *sem) |
25 | { |
26 | return svcWaitSynchronization(*sem, INT64_MAX); |
27 | } |
28 | |
29 | static inline int sem_destroy(sem_t *sem) |
30 | { |
31 | return svcCloseHandle(*sem); |
32 | } |
33 | |
34 | #endif //_3DS_SEMAPHORE_WRAP__ |
35 | |