VirtualBox

Changeset 22956 in vbox


Ignore:
Timestamp:
Sep 11, 2009 12:55:18 PM (15 years ago)
Author:
vboxsync
Message:

Runtime/semevent: clock_gettime(CLOCK_REALTIME) => RTTimeSystemNanoTS

Location:
trunk/src/VBox/Runtime/r3/linux
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/linux/semevent-linux.cpp

    r22955 r22956  
    5454#include <iprt/asm.h>
    5555#include <iprt/err.h>
     56#include <iprt/time.h>
    5657#include "internal/magics.h"
    5758
     
    197198     */
    198199    struct timespec ts;
    199     struct timespec tsEnd;
    200200    struct timespec *pTimeout = NULL;
     201    uint64_t u64End = 0; /* shut up gcc */
    201202    if (cMillies != RT_INDEFINITE_WAIT)
    202203    {
    203204        ts.tv_sec  = cMillies / 1000;
    204205        ts.tv_nsec = (cMillies % 1000) * 1000000;
    205         clock_gettime(CLOCK_REALTIME, &tsEnd);
    206         tsEnd.tv_sec  += ts.tv_sec;
    207         tsEnd.tv_nsec += ts.tv_nsec;
    208         if (tsEnd.tv_nsec >= 1000000000)
    209         {
    210             tsEnd.tv_nsec -= 1000000000;
    211             tsEnd.tv_sec++;
    212         }
     206        u64End = RTTimeSystemNanoTS() + cMillies * 1000000;
    213207        pTimeout = &ts;
    214208    }
     
    258252        if (pTimeout)
    259253        {
    260             clock_gettime(CLOCK_REALTIME, &ts);
    261             ts.tv_nsec = tsEnd.tv_nsec - ts.tv_nsec;
    262             ts.tv_sec  = tsEnd.tv_sec - ts.tv_sec;
    263             if (ts.tv_nsec < 0)
    264             {
    265                 ts.tv_nsec += 1000000000; /* not correct if ts.tv_sec is negative but we
    266                                              leave on negative timeouts in any case */
    267                 ts.tv_sec--;
    268             }
    269             /* don't wait for less than 1 microsecond */
    270             if (   ts.tv_sec < 0
    271                 || (ts.tv_sec == 0 && ts.tv_nsec < 1000))
     254            int64_t u64Diff = u64End - RTTimeSystemNanoTS();
     255            if (u64Diff < 1000)
    272256            {
    273257                rc = VERR_TIMEOUT;
    274258                break;
    275259            }
     260            ts.tv_sec  = u64Diff / 1000000000;
     261            ts.tv_nsec = u64Diff % 1000000000;
    276262        }
    277263    }
  • trunk/src/VBox/Runtime/r3/linux/semeventmulti-linux.cpp

    r22955 r22956  
    5656#include <iprt/asm.h>
    5757#include <iprt/err.h>
     58#include <iprt/time.h>
    5859#include "internal/magics.h"
    5960
     
    218219     */
    219220    struct timespec ts;
    220     struct timespec tsEnd;
    221221    struct timespec *pTimeout = NULL;
     222    uint64_t u64End = 0; /* shut up gcc */
    222223    if (cMillies != RT_INDEFINITE_WAIT)
    223224    {
    224225        ts.tv_sec  = cMillies / 1000;
    225226        ts.tv_nsec = (cMillies % 1000) * 1000000;
    226         clock_gettime(CLOCK_REALTIME, &tsEnd);
    227         tsEnd.tv_sec  += ts.tv_sec;
    228         tsEnd.tv_nsec += ts.tv_nsec;
    229         if (tsEnd.tv_nsec >= 1000000000)
    230         {
    231             tsEnd.tv_nsec -= 1000000000;
    232             tsEnd.tv_sec++;
    233         }
     227        u64End = RTTimeSystemNanoTS() + cMillies * 1000000;
    234228        pTimeout = &ts;
    235229    }
     
    252246            if (pTimeout)
    253247            {
    254                 clock_gettime(CLOCK_REALTIME, &ts);
    255                 ts.tv_nsec = tsEnd.tv_nsec - ts.tv_nsec;
    256                 ts.tv_sec  = tsEnd.tv_sec - ts.tv_sec;
    257                 if (ts.tv_nsec < 0)
    258                 {
    259                     ts.tv_nsec += 1000000000; /* not correct if ts.tv_sec is negative but we
    260                                                  leave on negative timeouts in any case */
    261                     ts.tv_sec--;
    262                 }
    263                 /* don't wait for less than 1 microsecond */
    264                 if (   ts.tv_sec < 0
    265                     || (ts.tv_sec == 0 && ts.tv_nsec < 1000))
     248                int64_t u64Diff = u64End - RTTimeSystemNanoTS();
     249                if (u64Diff < 1000)
    266250                    return VERR_TIMEOUT;
     251                ts.tv_sec  = u64Diff / 1000000000;
     252                ts.tv_nsec = u64Diff % 1000000000;
    267253            }
    268254            long rc = sys_futex(&pThis->iState, FUTEX_WAIT, 1, pTimeout, NULL, 0);
Note: See TracChangeset for help on using the changeset viewer.

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