1008
1009 if (thread != NULL &&
1010 thread->is_Watcher_thread() &&
1011 WatcherThread::watcher_thread()->has_crash_protection()) {
1012
1013 if (sig == SIGSEGV || sig == SIGBUS) {
1014 WatcherThread::watcher_thread()->crash_protection()->restore();
1015 }
1016 }
1017 }
1018
1019 #define assert_with_errno(cond, msg) \
1020 do { \
1021 int err = errno; \
1022 assert(cond, err_msg("%s; error='%s' (errno=%d)", msg, strerror(err), err)); \
1023 } while (false)
1024
1025 // POSIX unamed semaphores are not supported on OS X.
1026 #ifndef __APPLE__
1027
1028 Semaphore::Semaphore(uint value, uint /* max */) {
1029 int ret = sem_init(&_semaphore, 0, value);
1030
1031 assert_with_errno(ret == 0, "Failed to initialize semaphore");
1032 }
1033
1034 Semaphore::~Semaphore() {
1035 sem_destroy(&_semaphore);
1036 }
1037
1038 void Semaphore::signal() {
1039 int ret = sem_post(&_semaphore);
1040
1041 assert_with_errno(ret == 0, "sem_post failed");
1042 }
1043
1044 void Semaphore::signal(uint count) {
1045 for (uint i = 0; i < count; i++) {
1046 signal();
1047 }
1048 }
|
1008
1009 if (thread != NULL &&
1010 thread->is_Watcher_thread() &&
1011 WatcherThread::watcher_thread()->has_crash_protection()) {
1012
1013 if (sig == SIGSEGV || sig == SIGBUS) {
1014 WatcherThread::watcher_thread()->crash_protection()->restore();
1015 }
1016 }
1017 }
1018
1019 #define assert_with_errno(cond, msg) \
1020 do { \
1021 int err = errno; \
1022 assert(cond, err_msg("%s; error='%s' (errno=%d)", msg, strerror(err), err)); \
1023 } while (false)
1024
1025 // POSIX unamed semaphores are not supported on OS X.
1026 #ifndef __APPLE__
1027
1028 Semaphore::Semaphore(uint value) {
1029 int ret = sem_init(&_semaphore, 0, value);
1030
1031 assert_with_errno(ret == 0, "Failed to initialize semaphore");
1032 }
1033
1034 Semaphore::~Semaphore() {
1035 sem_destroy(&_semaphore);
1036 }
1037
1038 void Semaphore::signal() {
1039 int ret = sem_post(&_semaphore);
1040
1041 assert_with_errno(ret == 0, "sem_post failed");
1042 }
1043
1044 void Semaphore::signal(uint count) {
1045 for (uint i = 0; i < count; i++) {
1046 signal();
1047 }
1048 }
|