HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UT_Lockable.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_Lockable.h (UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  */
11 
12 #ifndef __UT_LOCKABLE_H_INCLUDED__
13 #define __UT_LOCKABLE_H_INCLUDED__
14 
15 #include "UT_API.h"
16 #include "UT_LockUtil.h"
17 #include "UT_NonCopyable.h"
18 #include <SYS/SYS_Types.h>
19 
20 /// UT_Lock interface adapter for C++11 mutexes
21 template <typename MUTEX>
23 {
24 public:
27 
30 
31  bool tryLock() { return myMutex.try_lock(); }
32  void lock() { myMutex.lock(); }
33  void unlock() { myMutex.unlock(); }
34  bool safeLock() { lock(); return true; }
35 
36  bool isLocked()
37  {
38  if (tryLock())
39  {
40  unlock();
41  return false;
42  }
43  return true;
44  }
45 
46  exint getMemoryUsage(bool inclusive) const
47  {
48  return (inclusive ? sizeof(*this) : 0);
49  }
50 
51 protected:
52  MUTEX& mutex() { return myMutex; }
53 
54 private:
55  MUTEX myMutex;
56 };
57 
58 #endif // __UT_LOCKABLE_H_INCLUDED__
void lock()
Definition: UT_Lockable.h:32
exint getMemoryUsage(bool inclusive) const
Definition: UT_Lockable.h:46
bool tryLock()
Definition: UT_Lockable.h:31
UT_Lock interface adapter for C++11 mutexes.
Definition: UT_Lockable.h:22
MUTEX & mutex()
Definition: UT_Lockable.h:52
int64 exint
Definition: SYS_Types.h:109
UT_LockScopeType< UT_Lockable< MUTEX > > Scope
Definition: UT_Lockable.h:29
bool safeLock()
Definition: UT_Lockable.h:34
void unlock()
Definition: UT_Lockable.h:33
bool isLocked()
Definition: UT_Lockable.h:36