VirtualBox

Changeset 102470 in vbox for trunk/src/libs/xpcom18a4


Ignore:
Timestamp:
Dec 5, 2023 11:03:48 AM (16 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
160613
Message:

libs/xpcom: Convert the PR_Wait() function to take the timeout in milliseconds and get rid of PR_Interval* and use RTTime*, bugref:10545 [2nd attempt]

Location:
trunk/src/libs/xpcom18a4
Files:
2 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/xpcom18a4/Makefile.kmk

    r102459 r102470  
    156156        nsprpub/lib/ds/plhash.h \
    157157        nsprpub/pr/include/prbit.h \
    158         nsprpub/pr/include/prinrval.h \
    159158        nsprpub/pr/include/prlong.h \
    160159        nsprpub/pr/include/prmem.h \
     
    384383        $(VBox-xpcom-nspr_0_OUTDIR)
    385384VBox-xpcom-nspr_SOURCES  = \
    386         nsprpub/pr/src/misc/prinrval.c \
    387385        nsprpub/lib/ds/plarena.c \
    388386        nsprpub/lib/ds/plhash.c \
  • trunk/src/libs/xpcom18a4/ipc/ipcd/client/public/ipcdclient.h

    r102392 r102470  
    5454#include "ipcIClientObserver.h"
    5555
    56 #include "prinrval.h"
     56#include <iprt/types.h>
    5757
    5858/* This API is only provided for the extensions compiled into the IPCDC
     
    240240  ipcIMessageObserver *aObserver = nsnull,
    241241  ipcIMessageObserver *aConsumer = nsnull,
    242   PRIntervalTime       aTimeout = PR_INTERVAL_NO_TIMEOUT
     242  RTMSINTERVAL        aTimeout = RT_INDEFINITE_WAIT
    243243);
    244244
  • trunk/src/libs/xpcom18a4/ipc/ipcd/client/src/ipcService.cpp

    r102392 r102470  
    105105{
    106106    return IPC_WaitMessage(aSenderID, aTarget, aObserver, nsnull,
    107                            PR_MillisecondsToInterval(aTimeout));
     107                           aTimeout);
    108108}
    109109
  • trunk/src/libs/xpcom18a4/ipc/ipcd/client/src/ipcdclient.cpp

    r102392 r102470  
    6666/* ------------------------------------------------------------------------- */
    6767
    68 #define IPC_REQUEST_TIMEOUT PR_SecondsToInterval(30)
     68#define IPC_REQUEST_TIMEOUT (30 * RT_MS_1SEC)
    6969
    7070/* ------------------------------------------------------------------------- */
     
    307307static nsresult
    308308WaitTarget(const nsID           &aTarget,
    309            PRIntervalTime        aTimeout,
     309           RTMSINTERVAL         aTimeout,
    310310           ipcMessage          **aMsg,
    311311           ipcMessageSelector    aSelector = nsnull,
     
    323323  PRBool isIPCMTarget = aTarget.Equals(IPCM_TARGET);
    324324
    325   PRIntervalTime timeStart = PR_IntervalNow();
    326   PRIntervalTime timeEnd;
    327   if (aTimeout == PR_INTERVAL_NO_TIMEOUT)
    328     timeEnd = aTimeout;
    329   else if (aTimeout == PR_INTERVAL_NO_WAIT)
     325  uint64_t timeStart = RTTimeProgramMilliTS();
     326  uint64_t timeEnd;
     327  if (aTimeout == RT_INDEFINITE_WAIT)
     328    timeEnd = UINT64_MAX;
     329  else if (aTimeout == 0)
    330330    timeEnd = timeStart;
    331331  else
     
    335335    // if overflowed, then set to max value
    336336    if (timeEnd < timeStart)
    337       timeEnd = PR_INTERVAL_NO_TIMEOUT;
     337      timeEnd = UINT64_MAX;
    338338  }
    339339
     
    440440#endif /* VBOX */
    441441
    442     PRIntervalTime t = PR_IntervalNow();
    443     if (t > timeEnd) // check if timeout has expired
     442    uint64_t t = RTTimeProgramMilliTS();
     443    if (   aTimeout != RT_INDEFINITE_WAIT
     444        && t > timeEnd) // check if timeout has expired
    444445    {
    445446      rv = IPC_ERROR_WOULD_BLOCK;
    446447      break;
    447448    }
    448     mon.Wait(timeEnd - t);
     449    mon.Wait(  aTimeout == RT_INDEFINITE_WAIT
     450             ? RT_INDEFINITE_WAIT
     451             : timeEnd - t);
    449452
    450453    Log(("woke up from sleep [pendingQempty=%d connected=%d shutdown=%d isIPCMTarget=%d]\n",
     
    10811084                ipcIMessageObserver *aObserver,
    10821085                ipcIMessageObserver *aConsumer,
    1083                 PRIntervalTime       aTimeout)
     1086                RTMSINTERVAL        aTimeout)
    10841087{
    10851088  NS_ENSURE_TRUE(gClientState, NS_ERROR_NOT_INITIALIZED);
  • trunk/src/libs/xpcom18a4/ipc/ipcd/extensions/dconnect/src/ipcDConnectService.cpp

    r102392 r102470  
    9696//-----------------------------------------------------------------------------
    9797
    98 #define DCON_WAIT_TIMEOUT PR_INTERVAL_NO_TIMEOUT
     98#define DCON_WAIT_TIMEOUT RT_INDEFINITE_WAIT
    9999
    100100//-----------------------------------------------------------------------------
     
    12811281    {
    12821282        uClient = aClient;
    1283         uTimestamp = PR_IntervalNow();
     1283        uTimestamp = RTTimeMilliTS();
    12841284    }
    12851285
    12861286    PRUint32 uClient;
    1287     PRIntervalTime uTimestamp;
     1287    uint64_t uTimestamp;
    12881288} ClientDownInfo;
    12891289typedef std::map<PRUint32, ClientDownInfo *> ClientDownMap;
     
    13261326        // Insert new client down information. Start by expiring outdated
    13271327        // entries and free one element if there's still no space (if needed).
    1328         PRIntervalTime now = PR_IntervalNow();
     1328        uint64_t now = RTTimeMilliTS();
    13291329        while (!g_ClientDownList.empty())
    13301330        {
     
    13321332            PRInt64 diff = (PRInt64)now - cInfo->uTimestamp;
    13331333            if (diff < 0)
    1334                 diff += (PRInt64)((PRIntervalTime)-1) + 1;
    1335             if (diff > PR_SecondsToInterval(15 * 60))
     1334                diff += (PRInt64)((uint64_t)-1) + 1;
     1335            if (diff > 15 * 60 * RT_MS_1SEC)
    13361336            {
    13371337                g_ClientDownMap.erase(cInfo->uClient);
     
    35573557    mon.Exit();
    35583558    {
    3559       PRUint32 ticks = PR_MillisecondsToInterval(PR_MIN(mWorkers.Count() / 20 + 1, 10));
    35603559      nsAutoMonitor workersMon(mWaitingWorkersMon);
    3561       workersMon.Wait(ticks);
     3560      workersMon.Wait(PR_MIN(mWorkers.Count() / 20 + 1, 10));
    35623561    }
    35633562    mon.Enter();
  • trunk/src/libs/xpcom18a4/ipc/ipcd/extensions/lock/src/ipcLockService.cpp

    r102392 r102470  
    109109        do {
    110110            // block the calling thread until we get a response from the daemon
    111             rv = IPC_WaitMessage(0, kLockTargetID, this, nsnull, PR_INTERVAL_NO_TIMEOUT);
     111            rv = IPC_WaitMessage(0, kLockTargetID, this, nsnull, RT_INDEFINITE_WAIT);
    112112        }
    113113        while (NS_SUCCEEDED(rv) && !pendingLock.complete);
  • trunk/src/libs/xpcom18a4/ipc/ipcd/extensions/transmngr/src/tmTransactionService.cpp

    r102458 r102470  
    327327                  aTrans->GetRawMessageLength());
    328328  if (aSync)
    329     IPC_WaitMessage(0, kTransModuleID, nsnull, nsnull, PR_INTERVAL_NO_TIMEOUT);
     329    IPC_WaitMessage(0, kTransModuleID, nsnull, nsnull, RT_INDEFINITE_WAIT);
    330330}
    331331
  • trunk/src/libs/xpcom18a4/nsprpub/pr/include/nspr.h

    r102459 r102470  
    4444
    4545#include "prbit.h"
    46 #include "prinrval.h"
    4746#include "prlong.h"
    4847#include "prmem.h"
  • trunk/src/libs/xpcom18a4/nsprpub/pr/include/prbit.h

    r102392 r102470  
    4646
    4747/*
    48 ** A prbitmap_t is a long integer that can be used for bitmaps
    49 */
    50 typedef unsigned long prbitmap_t;
    51 
    52 #define PR_TEST_BIT(_map,_bit) \
    53     ((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] & (1L << ((_bit) & (PR_BITS_PER_LONG-1))))
    54 #define PR_SET_BIT(_map,_bit) \
    55     ((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] |= (1L << ((_bit) & (PR_BITS_PER_LONG-1))))
    56 #define PR_CLEAR_BIT(_map,_bit) \
    57     ((_map)[(_bit)>>PR_BITS_PER_LONG_LOG2] &= ~(1L << ((_bit) & (PR_BITS_PER_LONG-1))))
    58 
    59 /*
    6048** Compute the log of the least power of 2 greater than or equal to n
    6149*/
     
    10088}
    10189
    102 /*
    103 ** Macro version of PR_CeilingLog2: Compute the log of the least power of
    104 ** 2 greater than or equal to _n. The result is returned in _log2.
    105 */
    106 #define PR_CEILING_LOG2(_log2,_n)   \
    107   PR_BEGIN_MACRO                    \
    108     PRUint32 j_ = (PRUint32)(_n);       \
    109     (_log2) = 0;                    \
    110     if ((j_) & ((j_)-1))            \
    111         (_log2) += 1;               \
    112     if ((j_) >> 16)                 \
    113         (_log2) += 16, (j_) >>= 16; \
    114     if ((j_) >> 8)                  \
    115         (_log2) += 8, (j_) >>= 8;   \
    116     if ((j_) >> 4)                  \
    117         (_log2) += 4, (j_) >>= 4;   \
    118     if ((j_) >> 2)                  \
    119         (_log2) += 2, (j_) >>= 2;   \
    120     if ((j_) >> 1)                  \
    121         (_log2) += 1;               \
    122   PR_END_MACRO
     90PR_END_EXTERN_C
    12391
    124 /*
    125 ** Macro version of PR_FloorLog2: Compute the log of the greatest power of
    126 ** 2 less than or equal to _n. The result is returned in _log2.
    127 **
    128 ** This is equivalent to finding the highest set bit in the word.
    129 */
    130 #define PR_FLOOR_LOG2(_log2,_n)   \
    131   PR_BEGIN_MACRO                    \
    132     PRUint32 j_ = (PRUint32)(_n);       \
    133     (_log2) = 0;                    \
    134     if ((j_) >> 16)                 \
    135         (_log2) += 16, (j_) >>= 16; \
    136     if ((j_) >> 8)                  \
    137         (_log2) += 8, (j_) >>= 8;   \
    138     if ((j_) >> 4)                  \
    139         (_log2) += 4, (j_) >>= 4;   \
    140     if ((j_) >> 2)                  \
    141         (_log2) += 2, (j_) >>= 2;   \
    142     if ((j_) >> 1)                  \
    143         (_log2) += 1;               \
    144   PR_END_MACRO
    145 
    146 PR_END_EXTERN_C
    14792#endif /* prbit_h___ */
  • trunk/src/libs/xpcom18a4/nsprpub/pr/include/prmon.h

    r102392 r102470  
    4040
    4141#include "prtypes.h"
    42 #include "prinrval.h"
     42
     43#include <iprt/types.h>
    4344
    4445#ifdef VBOX_WITH_XPCOM_NAMESPACE_CLEANUP
     
    105106** Returns PR_FAILURE if the caller has not entered the monitor.
    106107*/
    107 NSPR_API(PRStatus) PR_Wait(PRMonitor *mon, PRIntervalTime ticks);
     108NSPR_API(PRStatus) PR_Wait(PRMonitor *mon, RTMSINTERVAL msWait);
    108109
    109110/*
  • trunk/src/libs/xpcom18a4/nsprpub/pr/src/pthreads/ptsynch.c

    r102392 r102470  
    285285
    286286static PRIntn pt_TimedWait(
    287     pthread_cond_t *cv, pthread_mutex_t *ml, PRIntervalTime timeout)
     287    pthread_cond_t *cv, pthread_mutex_t *ml, RTMSINTERVAL msTimeout)
    288288{
    289289    int rv;
    290290    struct timeval now;
    291291    struct timespec tmo;
    292     PRUint32 ticks = PR_TicksPerSecond();
    293 
    294     tmo.tv_sec = (PRInt32)(timeout / ticks);
    295     tmo.tv_nsec = (PRInt32)(timeout - (tmo.tv_sec * ticks));
    296     tmo.tv_nsec = (PRInt32)PR_IntervalToMicroseconds(PT_NANOPERMICRO * tmo.tv_nsec);
     292
     293    tmo.tv_sec = (PRInt32)(msTimeout / RT_MS_1SEC);
     294    tmo.tv_nsec = (PRInt32)((msTimeout - (tmo.tv_sec * RT_MS_1SEC)) * RT_NS_1MS);
    297295
    298296    /* pthreads wants this in absolute time, off we go ... */
     
    367365}  /* PR_DestroyCondVar */
    368366
    369 PR_IMPLEMENT(PRStatus) PR_WaitCondVar(PRCondVar *cvar, PRIntervalTime timeout)
     367PR_IMPLEMENT(PRStatus) PR_WaitCondVar(PRCondVar *cvar, RTMSINTERVAL msTimeout)
    370368{
    371369    PRIntn rv;
     
    394392    cvar->lock->locked = PR_FALSE;
    395393
    396     if (timeout == PR_INTERVAL_NO_TIMEOUT)
     394    if (msTimeout == RT_INDEFINITE_WAIT)
    397395        rv = pthread_cond_wait(&cvar->cv, &cvar->lock->mutex);
    398396    else
    399         rv = pt_TimedWait(&cvar->cv, &cvar->lock->mutex, timeout);
     397        rv = pt_TimedWait(&cvar->cv, &cvar->lock->mutex, msTimeout);
    400398
    401399    /* We just got the lock back - this better be empty */
     
    545543}  /* PR_ExitMonitor */
    546544
    547 PR_IMPLEMENT(PRStatus) PR_Wait(PRMonitor *mon, PRIntervalTime timeout)
     545PR_IMPLEMENT(PRStatus) PR_Wait(PRMonitor *mon, RTMSINTERVAL msTimeout)
    548546{
    549547    PRStatus rv;
     
    565563    _PT_PTHREAD_INVALIDATE_THR_HANDLE(mon->owner);
    566564   
    567     rv = PR_WaitCondVar(mon->cvar, timeout);
     565    rv = PR_WaitCondVar(mon->cvar, msTimeout);
    568566
    569567    /* reinstate the intresting information */
  • trunk/src/libs/xpcom18a4/xpcom/reflect/xptcall/tests/TestXPTCInvoke.cpp

    r102392 r102470  
    4444#include "xptcall.h"
    4545#include "prlong.h"
    46 #include "prinrval.h"
    4746#include "nsMemory.h"
    4847
     
    5453
    5554#include <iprt/string.h>
     55#include <iprt/time.h>
    5656
    5757static char  g_szDirect[16384];
     
    14381438    static const int count = 100000000;
    14391439    int i;
    1440     PRIntervalTime start;
    1441     PRIntervalTime interval_direct;
    1442     PRIntervalTime interval_invoke;
     1440    uint64_t start;
     1441    uint64_t interval_direct;
     1442    uint64_t interval_invoke;
    14431443
    14441444    printf("Speed test...\n\n");
    14451445    printf("Doing %d direct call iterations...\n", count);
    1446     start = PR_IntervalNow();
     1446    start = RTTimeNanoTS();
    14471447    for(i = count; i; i--)
    14481448        (void)test->AddTwoInts(in1, in2, &out);
    1449     interval_direct = PR_IntervalNow() - start;
     1449    interval_direct = RTTimeNanoTS() - start;
    14501450
    14511451    printf("Doing %d invoked call iterations...\n", count);
    1452     start = PR_IntervalNow();
     1452    start = RTTimeNanoTS();
    14531453    for(i = count; i; i--)
    14541454        (void)XPTC_InvokeByIndex(test, 3, 3, var);
    1455     interval_invoke = PR_IntervalNow() - start;
     1455    interval_invoke = RTTimeNanoTS() - start;
    14561456
    14571457    printf(" direct took %0.2f seconds\n",
    1458             (double)interval_direct/(double)PR_TicksPerSecond());
     1458            (double)interval_direct/(double)RT_NS_1SEC);
    14591459    printf(" invoke took %0.2f seconds\n",
    1460             (double)interval_invoke/(double)PR_TicksPerSecond());
     1460            (double)interval_invoke/(double)RT_NS_1SEC);
    14611461    printf(" So, invoke overhead was ~ %0.2f seconds (~ %0.0f%%)\n",
    1462             (double)(interval_invoke-interval_direct)/(double)PR_TicksPerSecond(),
     1462            (double)(interval_invoke-interval_direct)/(double)RT_NS_1SEC,
    14631463            (double)(interval_invoke-interval_direct)/(double)interval_invoke*100);
    14641464}       
  • trunk/src/libs/xpcom18a4/xpcom/threads/nsAutoLock.h

    r102392 r102470  
    257257     * @see prmon.h
    258258     **/     
    259     nsresult Wait(PRIntervalTime interval = PR_INTERVAL_NO_TIMEOUT) {
    260         return PR_Wait(mMonitor, interval) == PR_SUCCESS
     259    nsresult Wait(RTMSINTERVAL msTimeout = RT_INDEFINITE_WAIT) {
     260        return PR_Wait(mMonitor, msTimeout) == PR_SUCCESS
    261261            ? NS_OK : NS_ERROR_FAILURE;
    262262    }
  • trunk/src/libs/xpcom18a4/xpcom/threads/plevent.c

    r102460 r102470  
    634634        PRStatus err;
    635635        Log(("$$$ waiting for event"));
    636         err = PR_Wait(mon, PR_INTERVAL_NO_TIMEOUT);
     636        err = PR_Wait(mon, RT_INDEFINITE_WAIT);
    637637    }
    638638
Note: See TracChangeset for help on using the changeset viewer.

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