Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | ** File: prinrval.h |
michael@0 | 8 | ** Description: API to interval timing functions of NSPR. |
michael@0 | 9 | ** |
michael@0 | 10 | ** |
michael@0 | 11 | ** NSPR provides interval times that are independent of network time |
michael@0 | 12 | ** of day values. Interval times are (in theory) accurate regardless |
michael@0 | 13 | ** of host processing requirements and also very cheap to acquire. It |
michael@0 | 14 | ** is expected that getting an interval time while in a synchronized |
michael@0 | 15 | ** function (holding one's lock). |
michael@0 | 16 | **/ |
michael@0 | 17 | |
michael@0 | 18 | #if !defined(prinrval_h) |
michael@0 | 19 | #define prinrval_h |
michael@0 | 20 | |
michael@0 | 21 | #include "prtypes.h" |
michael@0 | 22 | |
michael@0 | 23 | PR_BEGIN_EXTERN_C |
michael@0 | 24 | |
michael@0 | 25 | /**********************************************************************/ |
michael@0 | 26 | /************************* TYPES AND CONSTANTS ************************/ |
michael@0 | 27 | /**********************************************************************/ |
michael@0 | 28 | |
michael@0 | 29 | typedef PRUint32 PRIntervalTime; |
michael@0 | 30 | |
michael@0 | 31 | /*********************************************************************** |
michael@0 | 32 | ** DEFINES: PR_INTERVAL_MIN |
michael@0 | 33 | ** PR_INTERVAL_MAX |
michael@0 | 34 | ** DESCRIPTION: |
michael@0 | 35 | ** These two constants define the range (in ticks / second) of the |
michael@0 | 36 | ** platform dependent type, PRIntervalTime. These constants bound both |
michael@0 | 37 | ** the period and the resolution of a PRIntervalTime. |
michael@0 | 38 | ***********************************************************************/ |
michael@0 | 39 | #define PR_INTERVAL_MIN 1000UL |
michael@0 | 40 | #define PR_INTERVAL_MAX 100000UL |
michael@0 | 41 | |
michael@0 | 42 | /*********************************************************************** |
michael@0 | 43 | ** DEFINES: PR_INTERVAL_NO_WAIT |
michael@0 | 44 | ** PR_INTERVAL_NO_TIMEOUT |
michael@0 | 45 | ** DESCRIPTION: |
michael@0 | 46 | ** Two reserved constants are defined in the PRIntervalTime namespace. |
michael@0 | 47 | ** They are used to indicate that the process should wait no time (return |
michael@0 | 48 | ** immediately) or wait forever (never time out), respectively. |
michael@0 | 49 | ** Note: PR_INTERVAL_NO_TIMEOUT passed as input to PR_Connect is |
michael@0 | 50 | ** interpreted as use the OS's connect timeout. |
michael@0 | 51 | ** |
michael@0 | 52 | ***********************************************************************/ |
michael@0 | 53 | #define PR_INTERVAL_NO_WAIT 0UL |
michael@0 | 54 | #define PR_INTERVAL_NO_TIMEOUT 0xffffffffUL |
michael@0 | 55 | |
michael@0 | 56 | /**********************************************************************/ |
michael@0 | 57 | /****************************** FUNCTIONS *****************************/ |
michael@0 | 58 | /**********************************************************************/ |
michael@0 | 59 | |
michael@0 | 60 | /*********************************************************************** |
michael@0 | 61 | ** FUNCTION: PR_IntervalNow |
michael@0 | 62 | ** DESCRIPTION: |
michael@0 | 63 | ** Return the value of NSPR's free running interval timer. That timer |
michael@0 | 64 | ** can be used to establish epochs and determine intervals (be computing |
michael@0 | 65 | ** the difference between two times). |
michael@0 | 66 | ** INPUTS: void |
michael@0 | 67 | ** OUTPUTS: void |
michael@0 | 68 | ** RETURN: PRIntervalTime |
michael@0 | 69 | ** |
michael@0 | 70 | ** SIDE EFFECTS: |
michael@0 | 71 | ** None |
michael@0 | 72 | ** RESTRICTIONS: |
michael@0 | 73 | ** The units of PRIntervalTime are platform dependent. They are chosen |
michael@0 | 74 | ** such that they are appropriate for the host OS, yet provide sufficient |
michael@0 | 75 | ** resolution and period to be useful to clients. |
michael@0 | 76 | ** MEMORY: N/A |
michael@0 | 77 | ** ALGORITHM: Platform dependent |
michael@0 | 78 | ***********************************************************************/ |
michael@0 | 79 | NSPR_API(PRIntervalTime) PR_IntervalNow(void); |
michael@0 | 80 | |
michael@0 | 81 | /*********************************************************************** |
michael@0 | 82 | ** FUNCTION: PR_TicksPerSecond |
michael@0 | 83 | ** DESCRIPTION: |
michael@0 | 84 | ** Return the number of ticks per second for PR_IntervalNow's clock. |
michael@0 | 85 | ** The value will be in the range [PR_INTERVAL_MIN..PR_INTERVAL_MAX]. |
michael@0 | 86 | ** INPUTS: void |
michael@0 | 87 | ** OUTPUTS: void |
michael@0 | 88 | ** RETURN: PRUint32 |
michael@0 | 89 | ** |
michael@0 | 90 | ** SIDE EFFECTS: |
michael@0 | 91 | ** None |
michael@0 | 92 | ** RESTRICTIONS: |
michael@0 | 93 | ** None |
michael@0 | 94 | ** MEMORY: N/A |
michael@0 | 95 | ** ALGORITHM: N/A |
michael@0 | 96 | ***********************************************************************/ |
michael@0 | 97 | NSPR_API(PRUint32) PR_TicksPerSecond(void); |
michael@0 | 98 | |
michael@0 | 99 | /*********************************************************************** |
michael@0 | 100 | ** FUNCTION: PR_SecondsToInterval |
michael@0 | 101 | ** PR_MillisecondsToInterval |
michael@0 | 102 | ** PR_MicrosecondsToInterval |
michael@0 | 103 | ** DESCRIPTION: |
michael@0 | 104 | ** Convert standard clock units to platform dependent intervals. |
michael@0 | 105 | ** INPUTS: PRUint32 |
michael@0 | 106 | ** OUTPUTS: void |
michael@0 | 107 | ** RETURN: PRIntervalTime |
michael@0 | 108 | ** |
michael@0 | 109 | ** SIDE EFFECTS: |
michael@0 | 110 | ** None |
michael@0 | 111 | ** RESTRICTIONS: |
michael@0 | 112 | ** Conversion may cause overflow, which is not reported. |
michael@0 | 113 | ** MEMORY: N/A |
michael@0 | 114 | ** ALGORITHM: N/A |
michael@0 | 115 | ***********************************************************************/ |
michael@0 | 116 | NSPR_API(PRIntervalTime) PR_SecondsToInterval(PRUint32 seconds); |
michael@0 | 117 | NSPR_API(PRIntervalTime) PR_MillisecondsToInterval(PRUint32 milli); |
michael@0 | 118 | NSPR_API(PRIntervalTime) PR_MicrosecondsToInterval(PRUint32 micro); |
michael@0 | 119 | |
michael@0 | 120 | /*********************************************************************** |
michael@0 | 121 | ** FUNCTION: PR_IntervalToSeconds |
michael@0 | 122 | ** PR_IntervalToMilliseconds |
michael@0 | 123 | ** PR_IntervalToMicroseconds |
michael@0 | 124 | ** DESCRIPTION: |
michael@0 | 125 | ** Convert platform dependent intervals to standard clock units. |
michael@0 | 126 | ** INPUTS: PRIntervalTime |
michael@0 | 127 | ** OUTPUTS: void |
michael@0 | 128 | ** RETURN: PRUint32 |
michael@0 | 129 | ** |
michael@0 | 130 | ** SIDE EFFECTS: |
michael@0 | 131 | ** None |
michael@0 | 132 | ** RESTRICTIONS: |
michael@0 | 133 | ** Conversion may cause overflow, which is not reported. |
michael@0 | 134 | ** MEMORY: N/A |
michael@0 | 135 | ** ALGORITHM: N/A |
michael@0 | 136 | ***********************************************************************/ |
michael@0 | 137 | NSPR_API(PRUint32) PR_IntervalToSeconds(PRIntervalTime ticks); |
michael@0 | 138 | NSPR_API(PRUint32) PR_IntervalToMilliseconds(PRIntervalTime ticks); |
michael@0 | 139 | NSPR_API(PRUint32) PR_IntervalToMicroseconds(PRIntervalTime ticks); |
michael@0 | 140 | |
michael@0 | 141 | PR_END_EXTERN_C |
michael@0 | 142 | |
michael@0 | 143 | |
michael@0 | 144 | #endif /* !defined(prinrval_h) */ |
michael@0 | 145 | |
michael@0 | 146 | /* prinrval.h */ |