25 namespace folly::portability::semaphore {
28 HANDLE sema{INVALID_HANDLE_VALUE};
32 int sem_init(sem_t*
s,
int shared,
unsigned int value) {
37 auto sem = CreateSemaphoreA(
nullptr, 0, SEM_VALUE_MAX,
nullptr);
41 auto ret =
new sem_t_();
48 int sem_destroy(sem_t* s) {
49 if (!CloseHandle((*s)->sema)) {
57 int sem_post(sem_t* s) {
58 std::lock_guard<std::mutex>
lock{(*s)->mtx};
59 if ((*s)->value < SEM_VALUE_MAX) {
60 if (++(*s)->value <= 0 && !ReleaseSemaphore((*s)->sema, 1,
nullptr)) {
72 int sem_trywait(sem_t* s) {
73 std::lock_guard<std::mutex>
lock{(*s)->mtx};
74 if ((*s)->value > 0) {
83 int sem_wait(sem_t* s) {
86 std::lock_guard<std::mutex>
lock{(*s)->mtx};
87 value = --(*s)->value;
91 if (WaitForSingleObject((*s)->sema, INFINITE) != WAIT_OBJECT_0) {
auto lock(Synchronized< D, M > &synchronized, Args &&...args)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)