Lines Matching refs:semaphore
55 void semaphore_free(semaphore_t* semaphore) { in semaphore_free() argument
56 if (!semaphore) return; in semaphore_free()
58 if (semaphore->fd != INVALID_FD) close(semaphore->fd); in semaphore_free()
59 osi_free(semaphore); in semaphore_free()
62 void semaphore_wait(semaphore_t* semaphore) { in semaphore_wait() argument
63 CHECK(semaphore != NULL); in semaphore_wait()
64 CHECK(semaphore->fd != INVALID_FD); in semaphore_wait()
67 if (eventfd_read(semaphore->fd, &value) == -1) in semaphore_wait()
72 bool semaphore_try_wait(semaphore_t* semaphore) { in semaphore_try_wait() argument
73 CHECK(semaphore != NULL); in semaphore_try_wait()
74 CHECK(semaphore->fd != INVALID_FD); in semaphore_try_wait()
76 int flags = fcntl(semaphore->fd, F_GETFL); in semaphore_try_wait()
82 if (fcntl(semaphore->fd, F_SETFL, flags | O_NONBLOCK) == -1) { in semaphore_try_wait()
90 if (eventfd_read(semaphore->fd, &value) == -1) rc = false; in semaphore_try_wait()
92 if (fcntl(semaphore->fd, F_SETFL, flags) == -1) in semaphore_try_wait()
98 void semaphore_post(semaphore_t* semaphore) { in semaphore_post() argument
99 CHECK(semaphore != NULL); in semaphore_post()
100 CHECK(semaphore->fd != INVALID_FD); in semaphore_post()
102 if (eventfd_write(semaphore->fd, 1ULL) == -1) in semaphore_post()
107 int semaphore_get_fd(const semaphore_t* semaphore) { in semaphore_get_fd() argument
108 CHECK(semaphore != NULL); in semaphore_get_fd()
109 CHECK(semaphore->fd != INVALID_FD); in semaphore_get_fd()
110 return semaphore->fd; in semaphore_get_fd()