michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: ** File: prinrval.h michael@0: ** Description: API to interval timing functions of NSPR. michael@0: ** michael@0: ** michael@0: ** NSPR provides interval times that are independent of network time michael@0: ** of day values. Interval times are (in theory) accurate regardless michael@0: ** of host processing requirements and also very cheap to acquire. It michael@0: ** is expected that getting an interval time while in a synchronized michael@0: ** function (holding one's lock). michael@0: **/ michael@0: michael@0: #if !defined(prinrval_h) michael@0: #define prinrval_h michael@0: michael@0: #include "prtypes.h" michael@0: michael@0: PR_BEGIN_EXTERN_C michael@0: michael@0: /**********************************************************************/ michael@0: /************************* TYPES AND CONSTANTS ************************/ michael@0: /**********************************************************************/ michael@0: michael@0: typedef PRUint32 PRIntervalTime; michael@0: michael@0: /*********************************************************************** michael@0: ** DEFINES: PR_INTERVAL_MIN michael@0: ** PR_INTERVAL_MAX michael@0: ** DESCRIPTION: michael@0: ** These two constants define the range (in ticks / second) of the michael@0: ** platform dependent type, PRIntervalTime. These constants bound both michael@0: ** the period and the resolution of a PRIntervalTime. michael@0: ***********************************************************************/ michael@0: #define PR_INTERVAL_MIN 1000UL michael@0: #define PR_INTERVAL_MAX 100000UL michael@0: michael@0: /*********************************************************************** michael@0: ** DEFINES: PR_INTERVAL_NO_WAIT michael@0: ** PR_INTERVAL_NO_TIMEOUT michael@0: ** DESCRIPTION: michael@0: ** Two reserved constants are defined in the PRIntervalTime namespace. michael@0: ** They are used to indicate that the process should wait no time (return michael@0: ** immediately) or wait forever (never time out), respectively. michael@0: ** Note: PR_INTERVAL_NO_TIMEOUT passed as input to PR_Connect is michael@0: ** interpreted as use the OS's connect timeout. michael@0: ** michael@0: ***********************************************************************/ michael@0: #define PR_INTERVAL_NO_WAIT 0UL michael@0: #define PR_INTERVAL_NO_TIMEOUT 0xffffffffUL michael@0: michael@0: /**********************************************************************/ michael@0: /****************************** FUNCTIONS *****************************/ michael@0: /**********************************************************************/ michael@0: michael@0: /*********************************************************************** michael@0: ** FUNCTION: PR_IntervalNow michael@0: ** DESCRIPTION: michael@0: ** Return the value of NSPR's free running interval timer. That timer michael@0: ** can be used to establish epochs and determine intervals (be computing michael@0: ** the difference between two times). michael@0: ** INPUTS: void michael@0: ** OUTPUTS: void michael@0: ** RETURN: PRIntervalTime michael@0: ** michael@0: ** SIDE EFFECTS: michael@0: ** None michael@0: ** RESTRICTIONS: michael@0: ** The units of PRIntervalTime are platform dependent. They are chosen michael@0: ** such that they are appropriate for the host OS, yet provide sufficient michael@0: ** resolution and period to be useful to clients. michael@0: ** MEMORY: N/A michael@0: ** ALGORITHM: Platform dependent michael@0: ***********************************************************************/ michael@0: NSPR_API(PRIntervalTime) PR_IntervalNow(void); michael@0: michael@0: /*********************************************************************** michael@0: ** FUNCTION: PR_TicksPerSecond michael@0: ** DESCRIPTION: michael@0: ** Return the number of ticks per second for PR_IntervalNow's clock. michael@0: ** The value will be in the range [PR_INTERVAL_MIN..PR_INTERVAL_MAX]. michael@0: ** INPUTS: void michael@0: ** OUTPUTS: void michael@0: ** RETURN: PRUint32 michael@0: ** michael@0: ** SIDE EFFECTS: michael@0: ** None michael@0: ** RESTRICTIONS: michael@0: ** None michael@0: ** MEMORY: N/A michael@0: ** ALGORITHM: N/A michael@0: ***********************************************************************/ michael@0: NSPR_API(PRUint32) PR_TicksPerSecond(void); michael@0: michael@0: /*********************************************************************** michael@0: ** FUNCTION: PR_SecondsToInterval michael@0: ** PR_MillisecondsToInterval michael@0: ** PR_MicrosecondsToInterval michael@0: ** DESCRIPTION: michael@0: ** Convert standard clock units to platform dependent intervals. michael@0: ** INPUTS: PRUint32 michael@0: ** OUTPUTS: void michael@0: ** RETURN: PRIntervalTime michael@0: ** michael@0: ** SIDE EFFECTS: michael@0: ** None michael@0: ** RESTRICTIONS: michael@0: ** Conversion may cause overflow, which is not reported. michael@0: ** MEMORY: N/A michael@0: ** ALGORITHM: N/A michael@0: ***********************************************************************/ michael@0: NSPR_API(PRIntervalTime) PR_SecondsToInterval(PRUint32 seconds); michael@0: NSPR_API(PRIntervalTime) PR_MillisecondsToInterval(PRUint32 milli); michael@0: NSPR_API(PRIntervalTime) PR_MicrosecondsToInterval(PRUint32 micro); michael@0: michael@0: /*********************************************************************** michael@0: ** FUNCTION: PR_IntervalToSeconds michael@0: ** PR_IntervalToMilliseconds michael@0: ** PR_IntervalToMicroseconds michael@0: ** DESCRIPTION: michael@0: ** Convert platform dependent intervals to standard clock units. michael@0: ** INPUTS: PRIntervalTime michael@0: ** OUTPUTS: void michael@0: ** RETURN: PRUint32 michael@0: ** michael@0: ** SIDE EFFECTS: michael@0: ** None michael@0: ** RESTRICTIONS: michael@0: ** Conversion may cause overflow, which is not reported. michael@0: ** MEMORY: N/A michael@0: ** ALGORITHM: N/A michael@0: ***********************************************************************/ michael@0: NSPR_API(PRUint32) PR_IntervalToSeconds(PRIntervalTime ticks); michael@0: NSPR_API(PRUint32) PR_IntervalToMilliseconds(PRIntervalTime ticks); michael@0: NSPR_API(PRUint32) PR_IntervalToMicroseconds(PRIntervalTime ticks); michael@0: michael@0: PR_END_EXTERN_C michael@0: michael@0: michael@0: #endif /* !defined(prinrval_h) */ michael@0: michael@0: /* prinrval.h */