1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/include/prinrval.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,146 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 +** File: prinrval.h 1.11 +** Description: API to interval timing functions of NSPR. 1.12 +** 1.13 +** 1.14 +** NSPR provides interval times that are independent of network time 1.15 +** of day values. Interval times are (in theory) accurate regardless 1.16 +** of host processing requirements and also very cheap to acquire. It 1.17 +** is expected that getting an interval time while in a synchronized 1.18 +** function (holding one's lock). 1.19 +**/ 1.20 + 1.21 +#if !defined(prinrval_h) 1.22 +#define prinrval_h 1.23 + 1.24 +#include "prtypes.h" 1.25 + 1.26 +PR_BEGIN_EXTERN_C 1.27 + 1.28 +/**********************************************************************/ 1.29 +/************************* TYPES AND CONSTANTS ************************/ 1.30 +/**********************************************************************/ 1.31 + 1.32 +typedef PRUint32 PRIntervalTime; 1.33 + 1.34 +/*********************************************************************** 1.35 +** DEFINES: PR_INTERVAL_MIN 1.36 +** PR_INTERVAL_MAX 1.37 +** DESCRIPTION: 1.38 +** These two constants define the range (in ticks / second) of the 1.39 +** platform dependent type, PRIntervalTime. These constants bound both 1.40 +** the period and the resolution of a PRIntervalTime. 1.41 +***********************************************************************/ 1.42 +#define PR_INTERVAL_MIN 1000UL 1.43 +#define PR_INTERVAL_MAX 100000UL 1.44 + 1.45 +/*********************************************************************** 1.46 +** DEFINES: PR_INTERVAL_NO_WAIT 1.47 +** PR_INTERVAL_NO_TIMEOUT 1.48 +** DESCRIPTION: 1.49 +** Two reserved constants are defined in the PRIntervalTime namespace. 1.50 +** They are used to indicate that the process should wait no time (return 1.51 +** immediately) or wait forever (never time out), respectively. 1.52 +** Note: PR_INTERVAL_NO_TIMEOUT passed as input to PR_Connect is 1.53 +** interpreted as use the OS's connect timeout. 1.54 +** 1.55 +***********************************************************************/ 1.56 +#define PR_INTERVAL_NO_WAIT 0UL 1.57 +#define PR_INTERVAL_NO_TIMEOUT 0xffffffffUL 1.58 + 1.59 +/**********************************************************************/ 1.60 +/****************************** FUNCTIONS *****************************/ 1.61 +/**********************************************************************/ 1.62 + 1.63 +/*********************************************************************** 1.64 +** FUNCTION: PR_IntervalNow 1.65 +** DESCRIPTION: 1.66 +** Return the value of NSPR's free running interval timer. That timer 1.67 +** can be used to establish epochs and determine intervals (be computing 1.68 +** the difference between two times). 1.69 +** INPUTS: void 1.70 +** OUTPUTS: void 1.71 +** RETURN: PRIntervalTime 1.72 +** 1.73 +** SIDE EFFECTS: 1.74 +** None 1.75 +** RESTRICTIONS: 1.76 +** The units of PRIntervalTime are platform dependent. They are chosen 1.77 +** such that they are appropriate for the host OS, yet provide sufficient 1.78 +** resolution and period to be useful to clients. 1.79 +** MEMORY: N/A 1.80 +** ALGORITHM: Platform dependent 1.81 +***********************************************************************/ 1.82 +NSPR_API(PRIntervalTime) PR_IntervalNow(void); 1.83 + 1.84 +/*********************************************************************** 1.85 +** FUNCTION: PR_TicksPerSecond 1.86 +** DESCRIPTION: 1.87 +** Return the number of ticks per second for PR_IntervalNow's clock. 1.88 +** The value will be in the range [PR_INTERVAL_MIN..PR_INTERVAL_MAX]. 1.89 +** INPUTS: void 1.90 +** OUTPUTS: void 1.91 +** RETURN: PRUint32 1.92 +** 1.93 +** SIDE EFFECTS: 1.94 +** None 1.95 +** RESTRICTIONS: 1.96 +** None 1.97 +** MEMORY: N/A 1.98 +** ALGORITHM: N/A 1.99 +***********************************************************************/ 1.100 +NSPR_API(PRUint32) PR_TicksPerSecond(void); 1.101 + 1.102 +/*********************************************************************** 1.103 +** FUNCTION: PR_SecondsToInterval 1.104 +** PR_MillisecondsToInterval 1.105 +** PR_MicrosecondsToInterval 1.106 +** DESCRIPTION: 1.107 +** Convert standard clock units to platform dependent intervals. 1.108 +** INPUTS: PRUint32 1.109 +** OUTPUTS: void 1.110 +** RETURN: PRIntervalTime 1.111 +** 1.112 +** SIDE EFFECTS: 1.113 +** None 1.114 +** RESTRICTIONS: 1.115 +** Conversion may cause overflow, which is not reported. 1.116 +** MEMORY: N/A 1.117 +** ALGORITHM: N/A 1.118 +***********************************************************************/ 1.119 +NSPR_API(PRIntervalTime) PR_SecondsToInterval(PRUint32 seconds); 1.120 +NSPR_API(PRIntervalTime) PR_MillisecondsToInterval(PRUint32 milli); 1.121 +NSPR_API(PRIntervalTime) PR_MicrosecondsToInterval(PRUint32 micro); 1.122 + 1.123 +/*********************************************************************** 1.124 +** FUNCTION: PR_IntervalToSeconds 1.125 +** PR_IntervalToMilliseconds 1.126 +** PR_IntervalToMicroseconds 1.127 +** DESCRIPTION: 1.128 +** Convert platform dependent intervals to standard clock units. 1.129 +** INPUTS: PRIntervalTime 1.130 +** OUTPUTS: void 1.131 +** RETURN: PRUint32 1.132 +** 1.133 +** SIDE EFFECTS: 1.134 +** None 1.135 +** RESTRICTIONS: 1.136 +** Conversion may cause overflow, which is not reported. 1.137 +** MEMORY: N/A 1.138 +** ALGORITHM: N/A 1.139 +***********************************************************************/ 1.140 +NSPR_API(PRUint32) PR_IntervalToSeconds(PRIntervalTime ticks); 1.141 +NSPR_API(PRUint32) PR_IntervalToMilliseconds(PRIntervalTime ticks); 1.142 +NSPR_API(PRUint32) PR_IntervalToMicroseconds(PRIntervalTime ticks); 1.143 + 1.144 +PR_END_EXTERN_C 1.145 + 1.146 + 1.147 +#endif /* !defined(prinrval_h) */ 1.148 + 1.149 +/* prinrval.h */