]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/mutex.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 ******************************************************************************
6 * Copyright (C) 1997-2013, International Business Machines
7 * Corporation and others. All Rights Reserved.
9 ******************************************************************************
11 //----------------------------------------------------------------------------
14 // Lightweight C++ wrapper for umtx_ C mutex functions
16 // Author: Alan Liu 1/31/97
18 // 06/04/97 helena Updated setImplementation as per feedback from 5/21 drop.
19 // 04/07/1999 srl refocused as a thin wrapper
21 //----------------------------------------------------------------------------
25 #include "unicode/utypes.h"
26 #include "unicode/uobject.h"
31 //----------------------------------------------------------------------------
32 // Code within that accesses shared static or global data should
33 // should instantiate a Mutex object while doing so. You should make your own
34 // private mutex where possible.
40 // void Function(int arg1, int arg2)
42 // static Object* foo; // Shared read-write object
43 // Mutex mutex(&myMutex); // or no args for the global lock
45 // // When 'mutex' goes out of scope and gets destroyed here, the lock is released
48 // Note: Do NOT use the form 'Mutex mutex();' as that merely forward-declares a function
49 // returning a Mutex. This is a common mistake which silently slips through the
53 class U_COMMON_API Mutex
: public UMemory
{
55 inline Mutex(UMutex
*mutex
= NULL
);
61 Mutex(const Mutex
&other
); // forbid copying of this class
62 Mutex
&operator=(const Mutex
&other
); // forbid copying of this class
65 inline Mutex::Mutex(UMutex
*mutex
)
71 inline Mutex::~Mutex()