123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #include "sem_iphone.h"
- #include <fcntl.h>
- #include <unistd.h>
- void cgsem_init(cgsem_t *);
- void cgsem_post(cgsem_t *);
- void cgsem_wait(cgsem_t *);
- void cgsem_destroy(cgsem_t *);
- 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 SemaphoreIphone::wait() {
- cgsem_wait(&sem);
- return OK;
- }
- Error SemaphoreIphone::post() {
- cgsem_post(&sem);
- return OK;
- }
- int SemaphoreIphone::get() const {
- return 0;
- }
- Semaphore *SemaphoreIphone::create_semaphore_iphone() {
- return memnew(SemaphoreIphone);
- }
- void SemaphoreIphone::make_default() {
- create_func = create_semaphore_iphone;
- }
- SemaphoreIphone::SemaphoreIphone() {
- cgsem_init(&sem);
- }
- SemaphoreIphone::~SemaphoreIphone() {
- cgsem_destroy(&sem);
- }
|