Home Libraries Author Links

Abstract Data Type StmOnce
[System: Operating System Dependent Facilities]

Collaboration diagram for Abstract Data Type StmOnce:

Detailed Description

A StmOnce object provides a thread safe means to initialize data once.

On Windows systems StmOnce operations are implemented using Windows Platform SDK functions, whereas on non-Windows systems they are implemented as thin wrappers of the corresponding POSIX.1c threads related functions.

Example:
   static StmOnce stmGetMsCountInitialized_ = StmOnceInit;
   static StmInt64 stmGetMsCountBase_ = 0;

   static void stmGetMsCountInitialize_ (void)
   {
       stmGetMsCountBase_ = stmGetMsTime ();
       return;
   }

   StmInt64 stmGetMsCount (void)
   {
       StmInt64 ret = -1;
       if (stmOnce (&stmGetMsCountInitialized_, stmGetMsCountInitialize_))
       {
           return ret;
       }
       if ((ret = stmGetMsTime ()) >= 0)
       {
           ret -= stmGetMsCountBase_;
       }
       return ret;
   }


Defines

#define StmOnceInit   StmOnceInitImpl_
 StmOnce initializer.

Typedefs

typedef StmOnceImpl_ StmOnce
 StmOnce type.

Functions

int stmOnce (StmOnce *once, void(*routine)(void))
 Execute routine at most once in a process.


Define Documentation

#define StmOnceInit   StmOnceInitImpl_

StmOnce initializer.

An object of abstract data type StmOnce shall be initilized with the initializer StmOnceInit.

Definition at line 282 of file system.h.


Typedef Documentation

typedef StmOnceImpl_ StmOnce

StmOnce type.

An object of abstract data type StmOnce is represented by its implementation.

A StmOnce object must not have automatic storage duration and shall be initilized with the initializer StmOnceInit.

Definition at line 275 of file system.h.


Function Documentation

int stmOnce ( StmOnce once,
void(*)(void)  routine 
)

Execute routine at most once in a process.

Parameters:
[in] once Pointer to the StmOnce object controlling the execution of routine.
[in] routine Pointer to the routine to be executed.
Effects:
The first call to stmOnce() by any thread in a process, with a pointer once to a given StmOnce object, shall call routine with no arguments. Subsequent calls of stmOnce() with a pointer to the same StmOnce object do not call routine. On return from stmOnce(), routine has completed.
The behavior of stmOnce() is undefined if the StmOnce opject pointed to by once has automatic storage duration or was not initialized by StmOnceInit.
Returns:
0 on success.

-1 on error. Then routine has not been executed and the variable errno contains the error's cause.

See also:
stmOnce, stmOnceInit.


© Copyright Tom Michaelis 2002-2007

Distributed under the SysToMath Software License (See the accompanying file license.txt or a copy at www.SysToMath.com).