]>
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"
32 * Mutex is a helper class for convenient locking and unlocking of a UMutex.
34 * Creating a local scope Mutex will lock a UMutex, holding the lock until the Mutex
37 * If no UMutex is specified, the ICU global mutex is implied.
42 * static UMutex *m = STATIC_NEW(UMutex);
46 * void Function(int arg1, int arg2)
48 * static Object* foo; // Shared read-write object
49 * Mutex mutex(myMutex()); // or no args for the global lock
51 * // When 'mutex' goes out of scope and gets destroyed here, the lock is released
54 * Note: Do NOT use the form 'Mutex mutex();' as that merely forward-declares a function
55 * returning a Mutex. This is a common mistake which silently slips through the
59 class U_COMMON_API Mutex
: public UMemory
{
61 Mutex(UMutex
*mutex
= nullptr) : fMutex(mutex
) {
68 Mutex(const Mutex
&other
) = delete; // forbid assigning of this class
69 Mutex
&operator=(const Mutex
&other
) = delete; // forbid copying of this class
70 void *operator new(size_t s
) = delete; // forbid heap allocation. Locals only.