123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #include "sem_osx.h"
- #include <fcntl.h>
- #include <unistd.h>
- void cgsem_init(cgsem_t *cgsem) {
- int flags, fd, i;
- pipe(cgsem->pipefd);
-
- for (i = 0; i < 2; i++) {
- fd = cgsem->pipefd[i];
- flags = fcntl(fd, F_GETFD, 0);
- flags |= FD_CLOEXEC;
- fcntl(fd, F_SETFD, flags);
- }
- }
- void cgsem_post(cgsem_t *cgsem) {
- const char buf = 1;
- write(cgsem->pipefd[1], &buf, 1);
- }
- void cgsem_wait(cgsem_t *cgsem) {
- char buf;
- read(cgsem->pipefd[0], &buf, 1);
- }
- void cgsem_destroy(cgsem_t *cgsem) {
- close(cgsem->pipefd[1]);
- close(cgsem->pipefd[0]);
- }
- #include "core/os/memory.h"
- #include <errno.h>
- Error SemaphoreOSX::wait() {
- cgsem_wait(&sem);
- return OK;
- }
- Error SemaphoreOSX::post() {
- cgsem_post(&sem);
- return OK;
- }
- int SemaphoreOSX::get() const {
- return 0;
- }
- Semaphore *SemaphoreOSX::create_semaphore_osx() {
- return memnew(SemaphoreOSX);
- }
- void SemaphoreOSX::make_default() {
- create_func = create_semaphore_osx;
- }
- SemaphoreOSX::SemaphoreOSX() {
- cgsem_init(&sem);
- }
- SemaphoreOSX::~SemaphoreOSX() {
- cgsem_destroy(&sem);
- }
|