intl/icu/source/common/mutex.h

Wed, 31 Dec 2014 07:22:50 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:22:50 +0100
branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
permissions
-rw-r--r--

Correct previous dual key logic pending first delivery installment.

michael@0 1 /*
michael@0 2 ******************************************************************************
michael@0 3 *
michael@0 4 * Copyright (C) 1997-2013, International Business Machines
michael@0 5 * Corporation and others. All Rights Reserved.
michael@0 6 *
michael@0 7 ******************************************************************************
michael@0 8 */
michael@0 9 //----------------------------------------------------------------------------
michael@0 10 // File: mutex.h
michael@0 11 //
michael@0 12 // Lightweight C++ wrapper for umtx_ C mutex functions
michael@0 13 //
michael@0 14 // Author: Alan Liu 1/31/97
michael@0 15 // History:
michael@0 16 // 06/04/97 helena Updated setImplementation as per feedback from 5/21 drop.
michael@0 17 // 04/07/1999 srl refocused as a thin wrapper
michael@0 18 //
michael@0 19 //----------------------------------------------------------------------------
michael@0 20 #ifndef MUTEX_H
michael@0 21 #define MUTEX_H
michael@0 22
michael@0 23 #include "unicode/utypes.h"
michael@0 24 #include "unicode/uobject.h"
michael@0 25 #include "umutex.h"
michael@0 26
michael@0 27 U_NAMESPACE_BEGIN
michael@0 28
michael@0 29 //----------------------------------------------------------------------------
michael@0 30 // Code within that accesses shared static or global data should
michael@0 31 // should instantiate a Mutex object while doing so. You should make your own
michael@0 32 // private mutex where possible.
michael@0 33
michael@0 34 // For example:
michael@0 35 //
michael@0 36 // UMutex myMutex;
michael@0 37 //
michael@0 38 // void Function(int arg1, int arg2)
michael@0 39 // {
michael@0 40 // static Object* foo; // Shared read-write object
michael@0 41 // Mutex mutex(&myMutex); // or no args for the global lock
michael@0 42 // foo->Method();
michael@0 43 // // When 'mutex' goes out of scope and gets destroyed here, the lock is released
michael@0 44 // }
michael@0 45 //
michael@0 46 // Note: Do NOT use the form 'Mutex mutex();' as that merely forward-declares a function
michael@0 47 // returning a Mutex. This is a common mistake which silently slips through the
michael@0 48 // compiler!!
michael@0 49 //
michael@0 50
michael@0 51 class U_COMMON_API Mutex : public UMemory {
michael@0 52 public:
michael@0 53 inline Mutex(UMutex *mutex = NULL);
michael@0 54 inline ~Mutex();
michael@0 55
michael@0 56 private:
michael@0 57 UMutex *fMutex;
michael@0 58
michael@0 59 Mutex(const Mutex &other); // forbid copying of this class
michael@0 60 Mutex &operator=(const Mutex &other); // forbid copying of this class
michael@0 61 };
michael@0 62
michael@0 63 inline Mutex::Mutex(UMutex *mutex)
michael@0 64 : fMutex(mutex)
michael@0 65 {
michael@0 66 umtx_lock(fMutex);
michael@0 67 }
michael@0 68
michael@0 69 inline Mutex::~Mutex()
michael@0 70 {
michael@0 71 umtx_unlock(fMutex);
michael@0 72 }
michael@0 73
michael@0 74 U_NAMESPACE_END
michael@0 75
michael@0 76 #endif //_MUTEX_
michael@0 77 //eof

mercurial