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