home *** CD-ROM | disk | FTP | other *** search
- /*==============================================================================
- Module Name: icritsec.hpp
-
- Description:
- "Critical section" class interface specification.
-
- Copyright: (C) Copyright IBM Corporation 1992
- All Rights Reserved
- Licensed Materials = Property of IBM
-
- Usage:
- This file is #include-d in programs needing use of OS/2 "critical
- sections."
-
- Notes:
-
- Related Topics:
-
- History:
- flag yymmdd who description
- ---- ------ --- -----------------------------------------------------------
- 920901 law Initial (from IThread work)
- ==============================================================================*/
- #if !defined( _ICRITSEC_ )
- #define _ICRITSEC_
-
- /*------------------------------------------------------------------------------
- Class Name: ICritSec
-
- Description:
- Critical section class.
-
- Usage:
- 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 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 is declared an instance of this class. For example:
- :xmp.
- {
- ICritSec lock;
- // Manipulate static data without interruption...
- }
- :exmp.
-
- Notes:
- 1. Care must be taken to avoid dangerous actions during the duration
- of the critical section. Typically, system calls should be avoided.
- If locks must be preserved beyond the scope of an ICritSec, semaphores
- should be used.
- 2. Please read the OS/2 Programming Reference information on
- DosEnterCritSec/DosExitCritSec.
-
- Related Topics:
- ------------------------------------------------------------------------------*/
- class ICritSec {
- public:
- // Ctor enters critical section.
- ICritSec();
- // Dtor exits.
- ~ICritSec();
- // Static count for diagnostics purposes.
- static unsigned long
- count;
- };
-
- #endif /* _ICRITSEC_ */