home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cset21v1.zip / IBMCPP / IBMCLASS / ICRITSEC.HPP < prev    next >
C/C++ Source or Header  |  1993-10-22  |  5KB  |  77 lines

  1. #ifndef _ICRITSEC_
  2. #define _ICRITSEC_
  3. /*******************************************************************************
  4. * FILE NAME: icritsec.hpp                                                      *
  5. *                                                                              *
  6. * DESCRIPTION:                                                                 *
  7. *   Declaration of the class(es):                                              *
  8. *     ICritSec - OS/2 "critical" section                                       *
  9. *                                                                              *
  10. * COPYRIGHT:                                                                   *
  11. *   Licensed Materials - Property of IBM                                       *
  12. *   (C) Copyright IBM Corporation 1992, 1993                                   *
  13. *   All Rights Reserved                                                        *
  14. *   US Government Users Restricted Rights - Use, duplication, or disclosure    *
  15. *   restricted by GSA ADP Schedule Contract with IBM Corp.                     *
  16. *                                                                              *
  17. *******************************************************************************/
  18. #ifndef _IBASE_
  19.   #include <ibase.hpp>
  20. #endif
  21.  
  22. /*----------------------------------------------------------------------------*/
  23. /* Align classes on four byte boundary.                                       */
  24. /*----------------------------------------------------------------------------*/
  25. #pragma pack(4)
  26.  
  27. class ICritSec : public IBase {
  28. /*******************************************************************************
  29. *  Instances of this class are declared within blocks considered to be         *
  30. *  critical sections.  Such blocks usually manipulate static data and need to  *
  31. *  do so without interruption from code that is executing in other threads.    *
  32. *                                                                              *
  33. *  Instances of this class guarantee that no other thread in the current       *
  34. *  process will execute between the object's construction and destruction.     *
  35. *                                                                              *
  36. *  Typically, code that must execute without interruption by other threads is  *
  37. *  partitioned into a separate block, delimited by {}.  Within that block an   *
  38. *  instance of this class is declared.                                         *
  39. *                                                                              *
  40. *  Note: While the critical section is executing, avoid actions that have the  *
  41. *        potential to interrupt it, such as system calls.  If you must         *
  42. *        preserve locks beyond the scope of an ICritSec, use semaphores as     *
  43. *        implemented by the IResourceLock class.                               *
  44. *                                                                              *
  45. *  The following example shows how the ICritSec class is used:                 *
  46. *                                                                              *
  47. *   {                                                                          *
  48. *   ICritSec lock;                                                             *
  49. *   // Manipulate static data without interruption...                          *
  50. *   }                                                                          *
  51. *******************************************************************************/
  52. public:
  53. /*------------------------ Constructor and Destructor --------------------------
  54. | All the function of this class is accomplished through its constructor and   |
  55. | destructor.  The constructor causes a critical section to be entered.  The   |
  56. | corresponding destructor exits the critical section.                         |
  57. ------------------------------------------------------------------------------*/
  58.   ICritSec();
  59.   ~ICritSec();
  60.  
  61. /*------------------------------- Diagnostics ----------------------------------
  62. | The following static member is provided for diagnostic purposes:             |
  63. |   count - Keeps track of the total number of critical sections entered, but  |
  64. |           not yet exited.  It is equivalent to the number of ICritSec        |
  65. |           objects in existence.                                              |
  66. ------------------------------------------------------------------------------*/
  67. static unsigned long
  68.   count;
  69. };
  70.  
  71. /*----------------------------------------------------------------------------*/
  72. /* Resume compiler default packing.                                           */
  73. /*----------------------------------------------------------------------------*/
  74. #pragma pack()
  75.  
  76. #endif /* _ICRITSEC_ */
  77.