< prev index next >

src/os/posix/vm/os_posix.cpp

Print this page




 998 
 999 void os::WatcherThreadCrashProtection::restore() {
1000   assert(WatcherThread::watcher_thread()->has_crash_protection(),
1001       "must have crash protection");
1002 
1003   siglongjmp(_jmpbuf, 1);
1004 }
1005 
1006 void os::WatcherThreadCrashProtection::check_crash_protection(int sig,
1007     Thread* thread) {
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 }




























































 998 
 999 void os::WatcherThreadCrashProtection::restore() {
1000   assert(WatcherThread::watcher_thread()->has_crash_protection(),
1001       "must have crash protection");
1002 
1003   siglongjmp(_jmpbuf, 1);
1004 }
1005 
1006 void os::WatcherThreadCrashProtection::check_crash_protection(int sig,
1007     Thread* thread) {
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 }
1049 
1050 void Semaphore::wait() {
1051   while (sem_wait(&_semaphore) == -1 && errno == EINTR) {
1052     // Retry if the wait was interrupted by a signal.
1053   }
1054 }
1055 
1056 bool os::PosixSemaphore::trywait() {
1057   return sem_trywait(&_semaphore) == 0;
1058 }
1059 
1060 bool os::PosixSemaphore::timedwait(const struct timespec ts) {
1061   while (1) {
1062     int result = sem_timedwait(&_semaphore, &ts);
1063     if (result == 0) {
1064       return true;
1065     } else if (errno == EINTR) {
1066       continue;
1067     } else if (errno == ETIMEDOUT) {
1068       return false;
1069     } else {
1070       return false;
1071     }
1072   }
1073 }
1074 
1075 #endif // __APPLE__
< prev index next >