nsprpub/pr/include/obsolete/pralarm.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /*
     7 ** File:		pralarm.h
     8 ** Description:	API to periodic alarms.
     9 **
    10 **
    11 ** Alarms are defined to invoke some client specified function at 
    12 ** a time in the future. The notification may be a one time event
    13 ** or repeated at a fixed interval. The interval at which the next
    14 ** notification takes place may be modified by the client code only
    15 ** during the respective notification.
    16 **
    17 ** The notification is delivered on a thread that is part of the
    18 ** alarm context (PRAlarm). The thread will inherit the priority
    19 ** of the Alarm creator.
    20 **
    21 ** Any number of periodic alarms (PRAlarmID) may be created within
    22 ** the context of a single alarm (PRAlarm). The notifications will be
    23 ** scheduled as close to the desired time as possible.
    24 **
    25 ** Repeating periodic notifies are expected to run at a fixed rate.
    26 ** That rate is expressed as some number of notifies per period where
    27 ** the period is much larger than a PRIntervalTime (see prinrval.h).
    28 */
    30 #if !defined(pralarm_h)
    31 #define pralarm_h
    33 #include "prtypes.h"
    34 #include "prinrval.h"
    37 PR_BEGIN_EXTERN_C
    39 /**********************************************************************/
    40 /************************* TYPES AND CONSTANTS ************************/
    41 /**********************************************************************/
    43 typedef struct PRAlarm PRAlarm;
    44 typedef struct PRAlarmID PRAlarmID;
    46 typedef PRBool (PR_CALLBACK *PRPeriodicAlarmFn)(
    47     PRAlarmID *id, void *clientData, PRUint32 late);
    49 /**********************************************************************/
    50 /****************************** FUNCTIONS *****************************/
    51 /**********************************************************************/
    53 /***********************************************************************
    54 ** FUNCTION:    PR_CreateAlarm
    55 ** DESCRIPTION:
    56 **  Create an alarm context.
    57 ** INPUTS:      void
    58 ** OUTPUTS:     None
    59 ** RETURN:      PRAlarm*
    60 **  
    61 ** SIDE EFFECTS:
    62 **  This creates an alarm context, which is an object used for subsequent
    63 **  notification creations. It also creates a thread that will be used to
    64 ** deliver the notifications that are expected to be defined. The client
    65 ** is resposible for destroying the context when appropriate.
    66 ** RESTRICTIONS:
    67 **  None. 
    68 ** MEMORY:      The object (PRAlarm) and a thread to support notifications.
    69 ** ALGORITHM:   N/A
    70 ***********************************************************************/
    71 NSPR_API(PRAlarm*) PR_CreateAlarm(void);
    73 /***********************************************************************
    74 ** FUNCTION:    PR_DestroyAlarm
    75 ** DESCRIPTION:
    76 **  Destroys the context created by PR_CreateAlarm().
    77 ** INPUTS:      PRAlarm*
    78 ** OUTPUTS:     None
    79 ** RETURN:      PRStatus
    80 **  
    81 ** SIDE EFFECTS:
    82 **  This destroys the context that was created by PR_CreateAlarm().
    83 **  If there are any active alarms (PRAlarmID), they will be cancelled.
    84 **  Once that is done, the thread that was used to deliver the alarms
    85 **  will be joined. 
    86 ** RESTRICTIONS:
    87 **  None. 
    88 ** MEMORY:      N/A
    89 ** ALGORITHM:   N/A
    90 ***********************************************************************/
    91 NSPR_API(PRStatus) PR_DestroyAlarm(PRAlarm *alarm);
    93 /***********************************************************************
    94 ** FUNCTION:    PR_SetAlarm
    95 ** DESCRIPTION:
    96 **  Creates a periodic notifier that is to be delivered to a specified
    97 **  function at some fixed interval.
    98 ** INPUTS:      PRAlarm *alarm              Parent alarm context
    99 **              PRIntervalTime period       Interval over which the notifies
   100 **                                          are delivered.
   101 **              PRUint32 rate               The rate within the interval that
   102 **                                          the notifies will be delivered.
   103 **              PRPeriodicAlarmFn function  Entry point where the notifies
   104 **                                          will be delivered.
   105 ** OUTPUTS:     None
   106 ** RETURN:      PRAlarmID*                  Handle to the notifier just created
   107 **                                          or NULL if the request failed.
   108 **  
   109 ** SIDE EFFECTS:
   110 **  A periodic notifier is created. The notifications will be delivered
   111 **  by the alarm's internal thread at a fixed interval whose rate is the
   112 **  number of interrupts per interval specified. The first notification
   113 **  will be delivered as soon as possible, and they will continue until
   114 **  the notifier routine indicates that they should cease of the alarm
   115 **  context is destroyed (PR_DestroyAlarm).
   116 ** RESTRICTIONS:
   117 **  None. 
   118 ** MEMORY:      Memory for the notifier object.
   119 ** ALGORITHM:   The rate at which notifications are delivered are stated
   120 **              to be "'rate' notifies per 'interval'". The exact time of
   121 **              the notification is computed based on a epoch established
   122 **              when the notifier was set. Each notification is delivered
   123 **              not ealier than the epoch plus the fixed rate times the
   124 **              notification sequence number. Such notifications have the
   125 **              potential to be late by not more than 'interval'/'rate'.
   126 **              The amount of lateness of one notification is taken into
   127 **              account on the next in an attempt to avoid long term slew.  
   128 ***********************************************************************/
   129 NSPR_API(PRAlarmID*) PR_SetAlarm(
   130     PRAlarm *alarm, PRIntervalTime period, PRUint32 rate,
   131     PRPeriodicAlarmFn function, void *clientData);
   133 /***********************************************************************
   134 ** FUNCTION:    PR_ResetAlarm
   135 ** DESCRIPTION:
   136 **  Resets an existing alarm.
   137 ** INPUTS:      PRAlarmID *id               Identify of the notifier.
   138 **              PRIntervalTime period       Interval over which the notifies
   139 **                                          are delivered.
   140 **              PRUint32 rate               The rate within the interval that
   141 **                                          the notifies will be delivered.
   142 ** OUTPUTS:     None
   143 ** RETURN:      PRStatus                    Indication of completion.
   144 **  
   145 ** SIDE EFFECTS:
   146 **  An existing alarm may have its period and rate redefined. The
   147 **  additional side effect is that the notifier's epoch is recomputed.
   148 **  The first notification delivered by the newly refreshed alarm is
   149 **  defined to be 'interval'/'rate' from the time of the reset.
   150 ** RESTRICTIONS:
   151 **  This function may only be called in the notifier for that alarm.
   152 ** MEMORY:      N/A.
   153 ** ALGORITHM:   See PR_SetAlarm().  
   154 ***********************************************************************/
   155 NSPR_API(PRStatus) PR_ResetAlarm(
   156 	PRAlarmID *id, PRIntervalTime period, PRUint32 rate);
   158 PR_END_EXTERN_C
   160 #endif /* !defined(pralarm_h) */
   162 /* prinrval.h */

mercurial