| OLD | NEW |
| (Empty) |
| 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | |
| 2 /* | |
| 3 * The contents of this file are subject to the Mozilla Public | |
| 4 * License Version 1.1 (the "License"); you may not use this file | |
| 5 * except in compliance with the License. You may obtain a copy of | |
| 6 * the License at http://www.mozilla.org/MPL/ | |
| 7 * | |
| 8 * Software distributed under the License is distributed on an "AS | |
| 9 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | |
| 10 * implied. See the License for the specific language governing | |
| 11 * rights and limitations under the License. | |
| 12 * | |
| 13 * The Original Code is the Netscape Portable Runtime (NSPR). | |
| 14 * | |
| 15 * The Initial Developer of the Original Code is Netscape | |
| 16 * Communications Corporation. Portions created by Netscape are | |
| 17 * Copyright (C) 1998-2000 Netscape Communications Corporation. All | |
| 18 * Rights Reserved. | |
| 19 * | |
| 20 * Contributor(s): | |
| 21 * | |
| 22 * Alternatively, the contents of this file may be used under the | |
| 23 * terms of the GNU General Public License Version 2 or later (the | |
| 24 * "GPL"), in which case the provisions of the GPL are applicable | |
| 25 * instead of those above. If you wish to allow use of your | |
| 26 * version of this file only under the terms of the GPL and not to | |
| 27 * allow others to use your version of this file under the MPL, | |
| 28 * indicate your decision by deleting the provisions above and | |
| 29 * replace them with the notice and other provisions required by | |
| 30 * the GPL. If you do not delete the provisions above, a recipient | |
| 31 * may use your version of this file under either the MPL or the | |
| 32 * GPL. | |
| 33 */ | |
| 34 | |
| 35 /* | |
| 36 ** File: pralarm.h | |
| 37 ** Description: API to periodic alarms. | |
| 38 ** | |
| 39 ** | |
| 40 ** Alarms are defined to invoke some client specified function at | |
| 41 ** a time in the future. The notification may be a one time event | |
| 42 ** or repeated at a fixed interval. The interval at which the next | |
| 43 ** notification takes place may be modified by the client code only | |
| 44 ** during the respective notification. | |
| 45 ** | |
| 46 ** The notification is delivered on a thread that is part of the | |
| 47 ** alarm context (PRAlarm). The thread will inherit the priority | |
| 48 ** of the Alarm creator. | |
| 49 ** | |
| 50 ** Any number of periodic alarms (PRAlarmID) may be created within | |
| 51 ** the context of a single alarm (PRAlarm). The notifications will be | |
| 52 ** scheduled as close to the desired time as possible. | |
| 53 ** | |
| 54 ** Repeating periodic notifies are expected to run at a fixed rate. | |
| 55 ** That rate is expressed as some number of notifies per period where | |
| 56 ** the period is much larger than a PRIntervalTime (see prinrval.h). | |
| 57 */ | |
| 58 | |
| 59 #if !defined(pralarm_h) | |
| 60 #define pralarm_h | |
| 61 | |
| 62 #include "prtypes.h" | |
| 63 #include "prinrval.h" | |
| 64 | |
| 65 | |
| 66 PR_BEGIN_EXTERN_C | |
| 67 | |
| 68 /**********************************************************************/ | |
| 69 /************************* TYPES AND CONSTANTS ************************/ | |
| 70 /**********************************************************************/ | |
| 71 | |
| 72 typedef struct PRAlarm PRAlarm; | |
| 73 typedef struct PRAlarmID PRAlarmID; | |
| 74 | |
| 75 typedef PRBool (PR_CALLBACK *PRPeriodicAlarmFn)( | |
| 76 PRAlarmID *id, void *clientData, PRUint32 late); | |
| 77 | |
| 78 /**********************************************************************/ | |
| 79 /****************************** FUNCTIONS *****************************/ | |
| 80 /**********************************************************************/ | |
| 81 | |
| 82 /*********************************************************************** | |
| 83 ** FUNCTION: PR_CreateAlarm | |
| 84 ** DESCRIPTION: | |
| 85 ** Create an alarm context. | |
| 86 ** INPUTS: void | |
| 87 ** OUTPUTS: None | |
| 88 ** RETURN: PRAlarm* | |
| 89 ** | |
| 90 ** SIDE EFFECTS: | |
| 91 ** This creates an alarm context, which is an object used for subsequent | |
| 92 ** notification creations. It also creates a thread that will be used to | |
| 93 ** deliver the notifications that are expected to be defined. The client | |
| 94 ** is resposible for destroying the context when appropriate. | |
| 95 ** RESTRICTIONS: | |
| 96 ** None. | |
| 97 ** MEMORY: The object (PRAlarm) and a thread to support notifications. | |
| 98 ** ALGORITHM: N/A | |
| 99 ***********************************************************************/ | |
| 100 NSPR_API(PRAlarm*) PR_CreateAlarm(void); | |
| 101 | |
| 102 /*********************************************************************** | |
| 103 ** FUNCTION: PR_DestroyAlarm | |
| 104 ** DESCRIPTION: | |
| 105 ** Destroys the context created by PR_CreateAlarm(). | |
| 106 ** INPUTS: PRAlarm* | |
| 107 ** OUTPUTS: None | |
| 108 ** RETURN: PRStatus | |
| 109 ** | |
| 110 ** SIDE EFFECTS: | |
| 111 ** This destroys the context that was created by PR_CreateAlarm(). | |
| 112 ** If there are any active alarms (PRAlarmID), they will be cancelled. | |
| 113 ** Once that is done, the thread that was used to deliver the alarms | |
| 114 ** will be joined. | |
| 115 ** RESTRICTIONS: | |
| 116 ** None. | |
| 117 ** MEMORY: N/A | |
| 118 ** ALGORITHM: N/A | |
| 119 ***********************************************************************/ | |
| 120 NSPR_API(PRStatus) PR_DestroyAlarm(PRAlarm *alarm); | |
| 121 | |
| 122 /*********************************************************************** | |
| 123 ** FUNCTION: PR_SetAlarm | |
| 124 ** DESCRIPTION: | |
| 125 ** Creates a periodic notifier that is to be delivered to a specified | |
| 126 ** function at some fixed interval. | |
| 127 ** INPUTS: PRAlarm *alarm Parent alarm context | |
| 128 ** PRIntervalTime period Interval over which the notifies | |
| 129 ** are delivered. | |
| 130 ** PRUint32 rate The rate within the interval that | |
| 131 ** the notifies will be delivered. | |
| 132 ** PRPeriodicAlarmFn function Entry point where the notifies | |
| 133 ** will be delivered. | |
| 134 ** OUTPUTS: None | |
| 135 ** RETURN: PRAlarmID* Handle to the notifier just created | |
| 136 ** or NULL if the request failed. | |
| 137 ** | |
| 138 ** SIDE EFFECTS: | |
| 139 ** A periodic notifier is created. The notifications will be delivered | |
| 140 ** by the alarm's internal thread at a fixed interval whose rate is the | |
| 141 ** number of interrupts per interval specified. The first notification | |
| 142 ** will be delivered as soon as possible, and they will continue until | |
| 143 ** the notifier routine indicates that they should cease of the alarm | |
| 144 ** context is destroyed (PR_DestroyAlarm). | |
| 145 ** RESTRICTIONS: | |
| 146 ** None. | |
| 147 ** MEMORY: Memory for the notifier object. | |
| 148 ** ALGORITHM: The rate at which notifications are delivered are stated | |
| 149 ** to be "'rate' notifies per 'interval'". The exact time of | |
| 150 ** the notification is computed based on a epoch established | |
| 151 ** when the notifier was set. Each notification is delivered | |
| 152 ** not ealier than the epoch plus the fixed rate times the | |
| 153 ** notification sequence number. Such notifications have the | |
| 154 ** potential to be late by not more than 'interval'/'rate'. | |
| 155 ** The amount of lateness of one notification is taken into | |
| 156 ** account on the next in an attempt to avoid long term slew. | |
| 157 ***********************************************************************/ | |
| 158 NSPR_API(PRAlarmID*) PR_SetAlarm( | |
| 159 PRAlarm *alarm, PRIntervalTime period, PRUint32 rate, | |
| 160 PRPeriodicAlarmFn function, void *clientData); | |
| 161 | |
| 162 /*********************************************************************** | |
| 163 ** FUNCTION: PR_ResetAlarm | |
| 164 ** DESCRIPTION: | |
| 165 ** Resets an existing alarm. | |
| 166 ** INPUTS: PRAlarmID *id Identify of the notifier. | |
| 167 ** PRIntervalTime period Interval over which the notifies | |
| 168 ** are delivered. | |
| 169 ** PRUint32 rate The rate within the interval that | |
| 170 ** the notifies will be delivered. | |
| 171 ** OUTPUTS: None | |
| 172 ** RETURN: PRStatus Indication of completion. | |
| 173 ** | |
| 174 ** SIDE EFFECTS: | |
| 175 ** An existing alarm may have its period and rate redefined. The | |
| 176 ** additional side effect is that the notifier's epoch is recomputed. | |
| 177 ** The first notification delivered by the newly refreshed alarm is | |
| 178 ** defined to be 'interval'/'rate' from the time of the reset. | |
| 179 ** RESTRICTIONS: | |
| 180 ** This function may only be called in the notifier for that alarm. | |
| 181 ** MEMORY: N/A. | |
| 182 ** ALGORITHM: See PR_SetAlarm(). | |
| 183 ***********************************************************************/ | |
| 184 NSPR_API(PRStatus) PR_ResetAlarm( | |
| 185 PRAlarmID *id, PRIntervalTime period, PRUint32 rate); | |
| 186 | |
| 187 PR_END_EXTERN_C | |
| 188 | |
| 189 #endif /* !defined(pralarm_h) */ | |
| 190 | |
| 191 /* prinrval.h */ | |
| OLD | NEW |