home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Programming / ICU / src / icu / source / common / mutex.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-08-16  |  2.6 KB  |  91 lines

  1. /*
  2. *****************************************************************************************
  3. *                                                                                       *
  4. * COPYRIGHT:                                                                            *
  5. *   (C) Copyright Taligent, Inc.,  1997                                                 *
  6. *   (C) Copyright International Business Machines Corporation,  1997-1999               *
  7. *   Licensed Material - Program-Property of IBM - All Rights Reserved.                  *
  8. *   US Government Users Restricted Rights - Use, duplication, or disclosure             *
  9. *   restricted by GSA ADP Schedule Contract with IBM Corp.                              *
  10. *                                                                                       *
  11. *****************************************************************************************
  12. */
  13. //------------------------------------------------------------------------------
  14. // File:     mutex.h
  15. //
  16. // Lightweight C++ wrapper for umtx_ C mutex functions
  17. //
  18. // Author:   Alan Liu  1/31/97
  19. // History:
  20. // 06/04/97   helena         Updated setImplementation as per feedback from 5/21 drop.
  21. // 04/07/1999  srl               refocused as a thin wrapper
  22. //
  23. //------------------------------------------------------------------------------
  24. #ifndef MUTEX_H
  25. #define MUTEX_H
  26. #include "utypes.h"
  27.  
  28. #include "umutex.h"
  29.  
  30. //------------------------------------------------------------------------------
  31. // Code within this library which accesses protected data
  32. // should instantiate a Mutex object while doing so. You should make your own 
  33. // private mutex where possible.
  34.  
  35. // For example:
  36. // 
  37. // UMTX myMutex;
  38. // 
  39. // int InitializeMyMutex()
  40. // {
  41. //    umtx_init( &myMutex );
  42. //    return 0;
  43. // }
  44. // 
  45. // static int initializeMyMutex = InitializeMyMutex();
  46. //
  47. // void Function(int arg1, int arg2)
  48. // {
  49. //    static Object* foo; // Shared read-write object
  50. //    Mutex mutex(&myMutex);  // or no args for the global lock
  51. //    foo->Method();
  52. //    // When 'mutex' goes out of scope and gets destroyed here, the lock is released
  53. // }
  54. //
  55. // Note:  Do NOT use the form 'Mutex mutex();' as that merely forward-declares a function
  56. //        returning a Mutex. This is a common mistake which silently slips through the
  57. //        compiler!!
  58. //
  59.  
  60. class U_COMMON_API Mutex
  61. {
  62. public:
  63.   inline Mutex(UMTX *mutex = NULL);
  64.   inline ~Mutex();
  65.  
  66. private:
  67.   UMTX   *fMutex;
  68. };
  69.  
  70. inline Mutex::Mutex(UMTX *mutex)
  71.   : fMutex(mutex)
  72. {
  73.   umtx_lock(fMutex);
  74. }
  75.  
  76. inline Mutex::~Mutex()
  77. {
  78.   umtx_unlock(fMutex);
  79. }
  80.  
  81. #endif //_MUTEX_
  82. //eof
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.