3 /*-------------------------------------------------------------------------
4 * drawElements C++ Base Library
5 * -----------------------------
7 * Copyright 2014 The Android Open Source Project
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
23 * \brief deMutex C++ wrapper.
24 *//*--------------------------------------------------------------------*/
32 /*--------------------------------------------------------------------*//*!
33 * \brief Mutual exclusion lock
35 * Mutex class provides standard mutual exclusion lock functionality.
36 *//*--------------------------------------------------------------------*/
40 Mutex (deUint32 flags = 0);
43 void lock (void) throw();
44 void unlock (void) throw();
45 bool tryLock (void) throw();
48 Mutex (const Mutex& other); // Not allowed!
49 Mutex& operator= (const Mutex& other); // Not allowed!
54 /*--------------------------------------------------------------------*//*!
55 * \brief Scoped mutex lock.
57 * ScopedLock provides helper for maintaining Mutex lock for the duration
58 * of current scope. The lock is acquired in constructor and released
59 * when ScopedLock goes out of scope.
60 *//*--------------------------------------------------------------------*/
64 ScopedLock (Mutex& mutex);
65 ~ScopedLock (void) { m_mutex.unlock(); }
68 ScopedLock (const ScopedLock& other); // Not allowed!
69 ScopedLock& operator= (const ScopedLock& other); // Not allowed!
74 // Mutex inline implementations.
76 /*--------------------------------------------------------------------*//*!
77 * \brief Acquire mutex lock.
78 * \note This method will never report failure. If an error occurs due
79 * to misuse or other reason it will lead to process termination
82 * If mutex is currently locked the function will block until current
85 * In recursive mode further calls from the thread owning the mutex will
86 * succeed and increment lock count.
87 *//*--------------------------------------------------------------------*/
88 inline void Mutex::lock (void) throw()
90 deMutex_lock(m_mutex);
93 /*--------------------------------------------------------------------*//*!
94 * \brief Release mutex lock.
95 * \note This method will never report failure. If an error occurs due
96 * to misuse or other reason it will lead to process termination
99 * In recursive mode the mutex will be released once the lock count reaches
101 *//*--------------------------------------------------------------------*/
102 inline void Mutex::unlock (void) throw()
104 deMutex_unlock(m_mutex);
107 /*--------------------------------------------------------------------*//*!
108 * \brief Try to acquire lock.
109 * \return Returns true if lock was acquired and false otherwise.
111 * This function will never block, i.e. it will return false if mutex
112 * is currently locked.
113 *//*--------------------------------------------------------------------*/
114 inline bool Mutex::tryLock (void) throw()
116 return deMutex_tryLock(m_mutex) == DE_TRUE;
119 // ScopedLock inline implementations.
121 /*--------------------------------------------------------------------*//*!
122 * \brief Acquire scoped lock to mutex.
123 * \param mutex Mutex to be locked.
124 *//*--------------------------------------------------------------------*/
125 inline ScopedLock::ScopedLock (Mutex& mutex)
133 #endif // _DEMUTEX_HPP