VirtualBox

vbox的更動 43558 路徑 trunk/src/VBox/Runtime/r3/posix


忽略:
時間撮記:
2012-10-8 上午05:18:32 (12 年 以前)
作者:
vboxsync
訊息:

RT/Darwin: introduces simplefied phread_mutex_timedlock implementation for Darwin platform.

檔案:
修改 1 筆資料

圖例:

未更動
新增
刪除
  • trunk/src/VBox/Runtime/r3/posix/semmutex-posix.cpp

    r43363 r43558  
    6666};
    6767
     68#ifdef RT_OS_DARWIN
     69/**
     70 * This function emulate pthread_mutex_timedlock on Mac OS X
     71 */
     72static 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
    68101
    69102#undef RTSemMutexCreate
     
    242275    else
    243276    {
    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
    251279        struct timespec     ts = {0,0};
    252 #ifdef RT_OS_HAIKU
    253280        struct timeval      tv = {0,0};
    254281        gettimeofday(&tv, NULL);
     
    270297
    271298        /* take mutex */
     299#ifndef RT_OS_DARWIN
    272300        int rc = pthread_mutex_timedlock(&pThis->Mutex, &ts);
     301#else
     302        int rc = DarwinPthreadMutexTimedlock(&pThis->Mutex, &ts);
     303#endif
    273304        RTThreadUnblocked(hThreadSelf, RTTHREADSTATE_MUTEX);
    274305        if (rc)
     
    277308            return RTErrConvertFromErrno(rc);
    278309        }
    279 #endif /* !RT_OS_DARWIN */
    280310    }
    281311
注意: 瀏覽 TracChangeset 來幫助您使用更動檢視器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette