X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fruntime%2Fdarwin-os.c;h=df53e9878ded2a3f5124f6c7e6898c368b3544d0;hb=f7faed97898dd0e94a18b0d1fca03aaa0fe24ab0;hp=2d79d0664c639a0e13a60a7400fd3e7b03adb543;hpb=d3af5593ffff1c39a2f8fa8113704803f347e22f;p=sbcl.git diff --git a/src/runtime/darwin-os.c b/src/runtime/darwin-os.c index 2d79d06..df53e98 100644 --- a/src/runtime/darwin-os.c +++ b/src/runtime/darwin-os.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -36,8 +37,6 @@ os_get_runtime_executable_path(int external) if (_NSGetExecutablePath(path, &size) == -1) return NULL; - else - path[size] = '\0'; return copied_string(path); } @@ -166,5 +165,55 @@ mach_fork() { } } +void darwin_init(void) +{ + setup_mach_exception_handling_thread(); +} + #endif +#ifdef LISP_FEATURE_SB_THREAD + +inline void +os_sem_init(os_sem_t *sem, unsigned int value) +{ + if (KERN_SUCCESS!=semaphore_create(current_mach_task, sem, SYNC_POLICY_FIFO, (int)value)) + lose("os_sem_init(%p): %s", sem, strerror(errno)); +} + +inline void +os_sem_wait(os_sem_t *sem, char *what) +{ + kern_return_t ret; + restart: + FSHOW((stderr, "%s: os_sem_wait(%p)\n", what, sem)); + ret = semaphore_wait(*sem); + FSHOW((stderr, "%s: os_sem_wait(%p) => %s\n", what, sem, + KERN_SUCCESS==ret ? "ok" : strerror(errno))); + switch (ret) { + case KERN_SUCCESS: + return; + case KERN_OPERATION_TIMED_OUT: + fprintf(stderr, "%s: os_sem_wait(%p): %s", what, sem, strerror(errno)); + goto restart; + default: + lose("%s: os_sem_wait(%p): %s", what, sem, strerror(errno)); + } +} + +void +os_sem_post(os_sem_t *sem, char *what) +{ + if (KERN_SUCCESS!=semaphore_signal(*sem)) + lose("%s: os_sem_post(%p): %s", what, sem, strerror(errno)); + FSHOW((stderr, "%s: os_sem_post(%p) ok\n", what, sem)); +} + +void +os_sem_destroy(os_sem_t *sem) +{ + if (-1==semaphore_destroy(current_mach_task, *sem)) + lose("os_sem_destroy(%p): %s", sem, strerror(errno)); +} + +#endif