tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

pr_intervalnow.rst (1288B)


      1 PR_IntervalNow
      2 ==============
      3 
      4 Returns the value of NSPR's free-running interval timer.
      5 
      6 
      7 Syntax
      8 ------
      9 
     10 .. code::
     11 
     12    #include <prinrval.h>
     13 
     14    PRIntervalTime PR_IntervalNow(void);
     15 
     16 
     17 Returns
     18 ~~~~~~~
     19 
     20 A :ref:`PRIntervalTime` object.
     21 
     22 
     23 Description
     24 -----------
     25 
     26 You can use the value returned by ``PR_IntervalNow()`` to establish
     27 epochs and to determine intervals (that is, compute the difference
     28 between two times). ``PR_IntervalNow()`` is both very efficient and
     29 nonblocking, so it is appropriate to use (for example) while holding a
     30 mutex.
     31 
     32 The most common use for ``PR_IntervalNow()`` is to establish an epoch
     33 and test for the expiration of intervals. In this case, you typically
     34 call ``PR_IntervalNow()`` in a sequence that looks like this:
     35 
     36 .. code::
     37 
     38    PRUint32 interval = ... ; // milliseconds
     39    // ...
     40    PRStatus rv;
     41    PRIntervalTime epoch = PR_IntervalNow();
     42    PR_Lock(data->mutex);
     43    while (!EvaluateData(data))  /* wait until condition is met */
     44    {
     45        PRUint32 delta = PR_IntervalToMilliseconds(PR_IntervalNow() - epoch);
     46        if (delta > interval) break;  /* timeout */
     47        rv = PR_Wait(data->condition, PR_MillisecondsToInterval(interval - delta));
     48        if (PR_FAILURE == rv) break;  /* likely an interrupt */
     49    }
     50    PR_Unlock(data->mutex);