1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/nsprpub/pr/include/obsolete/pralarm.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,162 @@ 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: pralarm.h 1.11 +** Description: API to periodic alarms. 1.12 +** 1.13 +** 1.14 +** Alarms are defined to invoke some client specified function at 1.15 +** a time in the future. The notification may be a one time event 1.16 +** or repeated at a fixed interval. The interval at which the next 1.17 +** notification takes place may be modified by the client code only 1.18 +** during the respective notification. 1.19 +** 1.20 +** The notification is delivered on a thread that is part of the 1.21 +** alarm context (PRAlarm). The thread will inherit the priority 1.22 +** of the Alarm creator. 1.23 +** 1.24 +** Any number of periodic alarms (PRAlarmID) may be created within 1.25 +** the context of a single alarm (PRAlarm). The notifications will be 1.26 +** scheduled as close to the desired time as possible. 1.27 +** 1.28 +** Repeating periodic notifies are expected to run at a fixed rate. 1.29 +** That rate is expressed as some number of notifies per period where 1.30 +** the period is much larger than a PRIntervalTime (see prinrval.h). 1.31 +*/ 1.32 + 1.33 +#if !defined(pralarm_h) 1.34 +#define pralarm_h 1.35 + 1.36 +#include "prtypes.h" 1.37 +#include "prinrval.h" 1.38 + 1.39 + 1.40 +PR_BEGIN_EXTERN_C 1.41 + 1.42 +/**********************************************************************/ 1.43 +/************************* TYPES AND CONSTANTS ************************/ 1.44 +/**********************************************************************/ 1.45 + 1.46 +typedef struct PRAlarm PRAlarm; 1.47 +typedef struct PRAlarmID PRAlarmID; 1.48 + 1.49 +typedef PRBool (PR_CALLBACK *PRPeriodicAlarmFn)( 1.50 + PRAlarmID *id, void *clientData, PRUint32 late); 1.51 + 1.52 +/**********************************************************************/ 1.53 +/****************************** FUNCTIONS *****************************/ 1.54 +/**********************************************************************/ 1.55 + 1.56 +/*********************************************************************** 1.57 +** FUNCTION: PR_CreateAlarm 1.58 +** DESCRIPTION: 1.59 +** Create an alarm context. 1.60 +** INPUTS: void 1.61 +** OUTPUTS: None 1.62 +** RETURN: PRAlarm* 1.63 +** 1.64 +** SIDE EFFECTS: 1.65 +** This creates an alarm context, which is an object used for subsequent 1.66 +** notification creations. It also creates a thread that will be used to 1.67 +** deliver the notifications that are expected to be defined. The client 1.68 +** is resposible for destroying the context when appropriate. 1.69 +** RESTRICTIONS: 1.70 +** None. 1.71 +** MEMORY: The object (PRAlarm) and a thread to support notifications. 1.72 +** ALGORITHM: N/A 1.73 +***********************************************************************/ 1.74 +NSPR_API(PRAlarm*) PR_CreateAlarm(void); 1.75 + 1.76 +/*********************************************************************** 1.77 +** FUNCTION: PR_DestroyAlarm 1.78 +** DESCRIPTION: 1.79 +** Destroys the context created by PR_CreateAlarm(). 1.80 +** INPUTS: PRAlarm* 1.81 +** OUTPUTS: None 1.82 +** RETURN: PRStatus 1.83 +** 1.84 +** SIDE EFFECTS: 1.85 +** This destroys the context that was created by PR_CreateAlarm(). 1.86 +** If there are any active alarms (PRAlarmID), they will be cancelled. 1.87 +** Once that is done, the thread that was used to deliver the alarms 1.88 +** will be joined. 1.89 +** RESTRICTIONS: 1.90 +** None. 1.91 +** MEMORY: N/A 1.92 +** ALGORITHM: N/A 1.93 +***********************************************************************/ 1.94 +NSPR_API(PRStatus) PR_DestroyAlarm(PRAlarm *alarm); 1.95 + 1.96 +/*********************************************************************** 1.97 +** FUNCTION: PR_SetAlarm 1.98 +** DESCRIPTION: 1.99 +** Creates a periodic notifier that is to be delivered to a specified 1.100 +** function at some fixed interval. 1.101 +** INPUTS: PRAlarm *alarm Parent alarm context 1.102 +** PRIntervalTime period Interval over which the notifies 1.103 +** are delivered. 1.104 +** PRUint32 rate The rate within the interval that 1.105 +** the notifies will be delivered. 1.106 +** PRPeriodicAlarmFn function Entry point where the notifies 1.107 +** will be delivered. 1.108 +** OUTPUTS: None 1.109 +** RETURN: PRAlarmID* Handle to the notifier just created 1.110 +** or NULL if the request failed. 1.111 +** 1.112 +** SIDE EFFECTS: 1.113 +** A periodic notifier is created. The notifications will be delivered 1.114 +** by the alarm's internal thread at a fixed interval whose rate is the 1.115 +** number of interrupts per interval specified. The first notification 1.116 +** will be delivered as soon as possible, and they will continue until 1.117 +** the notifier routine indicates that they should cease of the alarm 1.118 +** context is destroyed (PR_DestroyAlarm). 1.119 +** RESTRICTIONS: 1.120 +** None. 1.121 +** MEMORY: Memory for the notifier object. 1.122 +** ALGORITHM: The rate at which notifications are delivered are stated 1.123 +** to be "'rate' notifies per 'interval'". The exact time of 1.124 +** the notification is computed based on a epoch established 1.125 +** when the notifier was set. Each notification is delivered 1.126 +** not ealier than the epoch plus the fixed rate times the 1.127 +** notification sequence number. Such notifications have the 1.128 +** potential to be late by not more than 'interval'/'rate'. 1.129 +** The amount of lateness of one notification is taken into 1.130 +** account on the next in an attempt to avoid long term slew. 1.131 +***********************************************************************/ 1.132 +NSPR_API(PRAlarmID*) PR_SetAlarm( 1.133 + PRAlarm *alarm, PRIntervalTime period, PRUint32 rate, 1.134 + PRPeriodicAlarmFn function, void *clientData); 1.135 + 1.136 +/*********************************************************************** 1.137 +** FUNCTION: PR_ResetAlarm 1.138 +** DESCRIPTION: 1.139 +** Resets an existing alarm. 1.140 +** INPUTS: PRAlarmID *id Identify of the notifier. 1.141 +** PRIntervalTime period Interval over which the notifies 1.142 +** are delivered. 1.143 +** PRUint32 rate The rate within the interval that 1.144 +** the notifies will be delivered. 1.145 +** OUTPUTS: None 1.146 +** RETURN: PRStatus Indication of completion. 1.147 +** 1.148 +** SIDE EFFECTS: 1.149 +** An existing alarm may have its period and rate redefined. The 1.150 +** additional side effect is that the notifier's epoch is recomputed. 1.151 +** The first notification delivered by the newly refreshed alarm is 1.152 +** defined to be 'interval'/'rate' from the time of the reset. 1.153 +** RESTRICTIONS: 1.154 +** This function may only be called in the notifier for that alarm. 1.155 +** MEMORY: N/A. 1.156 +** ALGORITHM: See PR_SetAlarm(). 1.157 +***********************************************************************/ 1.158 +NSPR_API(PRStatus) PR_ResetAlarm( 1.159 + PRAlarmID *id, PRIntervalTime period, PRUint32 rate); 1.160 + 1.161 +PR_END_EXTERN_C 1.162 + 1.163 +#endif /* !defined(pralarm_h) */ 1.164 + 1.165 +/* prinrval.h */