home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
ICRITSEC.HPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-22
|
5KB
|
77 lines
#ifndef _ICRITSEC_
#define _ICRITSEC_
/*******************************************************************************
* FILE NAME: icritsec.hpp *
* *
* DESCRIPTION: *
* Declaration of the class(es): *
* ICritSec - OS/2 "critical" section *
* *
* COPYRIGHT: *
* Licensed Materials - Property of IBM *
* (C) Copyright IBM Corporation 1992, 1993 *
* All Rights Reserved *
* US Government Users Restricted Rights - Use, duplication, or disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************/
#ifndef _IBASE_
#include <ibase.hpp>
#endif
/*----------------------------------------------------------------------------*/
/* Align classes on four byte boundary. */
/*----------------------------------------------------------------------------*/
#pragma pack(4)
class ICritSec : public IBase {
/*******************************************************************************
* Instances of this class are declared within blocks considered to be *
* critical sections. Such blocks usually manipulate static data and need to *
* do so without interruption from code that is executing in other threads. *
* *
* Instances of this class guarantee that no other thread in the current *
* process will execute between the object's construction and destruction. *
* *
* Typically, code that must execute without interruption by other threads is *
* partitioned into a separate block, delimited by {}. Within that block an *
* instance of this class is declared. *
* *
* Note: While the critical section is executing, avoid actions that have the *
* potential to interrupt it, such as system calls. If you must *
* preserve locks beyond the scope of an ICritSec, use semaphores as *
* implemented by the IResourceLock class. *
* *
* The following example shows how the ICritSec class is used: *
* *
* { *
* ICritSec lock; *
* // Manipulate static data without interruption... *
* } *
*******************************************************************************/
public:
/*------------------------ Constructor and Destructor --------------------------
| All the function of this class is accomplished through its constructor and |
| destructor. The constructor causes a critical section to be entered. The |
| corresponding destructor exits the critical section. |
------------------------------------------------------------------------------*/
ICritSec();
~ICritSec();
/*------------------------------- Diagnostics ----------------------------------
| The following static member is provided for diagnostic purposes: |
| count - Keeps track of the total number of critical sections entered, but |
| not yet exited. It is equivalent to the number of ICritSec |
| objects in existence. |
------------------------------------------------------------------------------*/
static unsigned long
count;
};
/*----------------------------------------------------------------------------*/
/* Resume compiler default packing. */
/*----------------------------------------------------------------------------*/
#pragma pack()
#endif /* _ICRITSEC_ */