Changeset 43558 in vbox
- Timestamp:
- Oct 8, 2012 5:18:32 AM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r3/posix/semmutex-posix.cpp
r43363 r43558 66 66 }; 67 67 68 #ifdef RT_OS_DARWIN 69 /** 70 * This function emulate pthread_mutex_timedlock on Mac OS X 71 */ 72 static int DarwinPthreadMutexTimedlock(pthread_mutex_t * mutex, const struct timespec * abs_timeout) 73 { 74 int rc = 0; 75 struct timeval tv; 76 struct timespec rt; 77 do 78 { 79 rc = pthread_mutex_trylock(mutex); 80 if (rc == EBUSY) 81 { 82 timespec ts; 83 ts.tv_sec = 0; 84 ts.tv_sec = 10000000; 85 86 int rcSleep = -1; 87 while (rcSleep == -1) 88 rcSleep = nanosleep(&ts, &ts); 89 } 90 else 91 break; 92 gettimeofday(&tv, NULL); 93 rt.tv_sec = abs_timeout->tv_sec - tv.tv_sec; 94 rt.tv_nsec = abs_timeout->tv_nsec - tv.tv_usec * 1000; 95 } while ( rc != 0 96 || rt.tv_sec < 0); 97 return rc; 98 } 99 #endif 100 68 101 69 102 #undef RTSemMutexCreate … … 242 275 else 243 276 { 244 #ifdef RT_OS_DARWIN 245 AssertMsgFailed(("Not implemented on Darwin yet because of incomplete pthreads API.")); 246 return VERR_NOT_IMPLEMENTED; 247 #else /* !RT_OS_DARWIN */ 248 /* 249 * Get current time and calc end of wait time. 250 */ 277 #if defined(RT_OS_DARWIN) || defined(RT_OS_HAIKU) 278 251 279 struct timespec ts = {0,0}; 252 #ifdef RT_OS_HAIKU253 280 struct timeval tv = {0,0}; 254 281 gettimeofday(&tv, NULL); … … 270 297 271 298 /* take mutex */ 299 #ifndef RT_OS_DARWIN 272 300 int rc = pthread_mutex_timedlock(&pThis->Mutex, &ts); 301 #else 302 int rc = DarwinPthreadMutexTimedlock(&pThis->Mutex, &ts); 303 #endif 273 304 RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_MUTEX); 274 305 if (rc) … … 277 308 return RTErrConvertFromErrno(rc); 278 309 } 279 #endif /* !RT_OS_DARWIN */280 310 } 281 311
Note:
See TracChangeset
for help on using the changeset viewer.