OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
lockmgr::MutexTracker Class Reference

#include <LockMgrImpl.h>

+ Inheritance diagram for lockmgr::MutexTracker:
+ Collaboration diagram for lockmgr::MutexTracker:

Public Member Functions

 MutexTracker (std::unique_ptr< heavyai::DistributedSharedMutex > dmutex)
 
virtual void lock ()
 
virtual bool try_lock ()
 
virtual void unlock ()
 
virtual void lock_shared ()
 
virtual bool try_lock_shared ()
 
virtual void unlock_shared ()
 
virtual bool isAcquired () const
 
- Public Member Functions inherited from heavyai::SharedMutexInterface
virtual ~SharedMutexInterface ()
 
- Public Member Functions inherited from heavyai::MutexInterface
virtual ~MutexInterface ()
 

Private Attributes

std::atomic< size_t > ref_count_
 
MutexTypeBase mutex_
 
std::unique_ptr
< heavyai::DistributedSharedMutex
dmutex_
 

Detailed Description

Definition at line 38 of file LockMgrImpl.h.

Constructor & Destructor Documentation

lockmgr::MutexTracker::MutexTracker ( std::unique_ptr< heavyai::DistributedSharedMutex dmutex)
inline

Definition at line 40 of file LockMgrImpl.h.

41  : ref_count_(0u), dmutex_(std::move(dmutex)) {}
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
Definition: LockMgrImpl.h:56
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:54

Member Function Documentation

virtual bool lockmgr::MutexTracker::isAcquired ( ) const
inlinevirtual

Definition at line 51 of file LockMgrImpl.h.

References ref_count_.

51 { return ref_count_.load() > 0; }
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:54
void lockmgr::MutexTracker::lock ( )
virtual

Implements heavyai::MutexInterface.

Definition at line 38 of file LockMgr.cpp.

References dmutex_, g_multi_instance, mutex_, and ref_count_.

38  {
39  ref_count_.fetch_add(1u);
40  if (!g_multi_instance) {
41  mutex_.lock();
42  } else {
43  dmutex_->lock();
44  }
45 }
MutexTypeBase mutex_
Definition: LockMgrImpl.h:55
bool g_multi_instance
Definition: heavyai_locks.h:22
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
Definition: LockMgrImpl.h:56
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:54
void lockmgr::MutexTracker::lock_shared ( )
virtual

Implements heavyai::SharedMutexInterface.

Definition at line 69 of file LockMgr.cpp.

References dmutex_, g_multi_instance, mutex_, and ref_count_.

69  {
70  ref_count_.fetch_add(1u);
71  if (!g_multi_instance) {
72  mutex_.lock_shared();
73  } else {
74  dmutex_->lock_shared();
75  }
76 }
MutexTypeBase mutex_
Definition: LockMgrImpl.h:55
bool g_multi_instance
Definition: heavyai_locks.h:22
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
Definition: LockMgrImpl.h:56
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:54
bool lockmgr::MutexTracker::try_lock ( )
virtual

Implements heavyai::MutexInterface.

Definition at line 47 of file LockMgr.cpp.

References dmutex_, g_multi_instance, mutex_, and ref_count_.

47  {
48  bool gotlock{false};
49  if (!g_multi_instance) {
50  gotlock = mutex_.try_lock();
51  } else {
52  gotlock = dmutex_->try_lock();
53  }
54  if (gotlock) {
55  ref_count_.fetch_add(1u);
56  }
57  return gotlock;
58 }
MutexTypeBase mutex_
Definition: LockMgrImpl.h:55
bool g_multi_instance
Definition: heavyai_locks.h:22
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
Definition: LockMgrImpl.h:56
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:54
bool lockmgr::MutexTracker::try_lock_shared ( )
virtual

Implements heavyai::SharedMutexInterface.

Definition at line 78 of file LockMgr.cpp.

References dmutex_, g_multi_instance, mutex_, and ref_count_.

78  {
79  bool gotlock{false};
80  if (!g_multi_instance) {
81  gotlock = mutex_.try_lock_shared();
82  } else {
83  gotlock = dmutex_->try_lock_shared();
84  }
85  if (gotlock) {
86  ref_count_.fetch_add(1u);
87  }
88  return gotlock;
89 }
MutexTypeBase mutex_
Definition: LockMgrImpl.h:55
bool g_multi_instance
Definition: heavyai_locks.h:22
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
Definition: LockMgrImpl.h:56
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:54
void lockmgr::MutexTracker::unlock ( )
virtual

Implements heavyai::MutexInterface.

Definition at line 60 of file LockMgr.cpp.

References dmutex_, g_multi_instance, mutex_, and ref_count_.

60  {
61  if (!g_multi_instance) {
62  mutex_.unlock();
63  } else {
64  dmutex_->unlock();
65  }
66  ref_count_.fetch_sub(1u);
67 }
MutexTypeBase mutex_
Definition: LockMgrImpl.h:55
bool g_multi_instance
Definition: heavyai_locks.h:22
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
Definition: LockMgrImpl.h:56
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:54
void lockmgr::MutexTracker::unlock_shared ( )
virtual

Implements heavyai::SharedMutexInterface.

Definition at line 91 of file LockMgr.cpp.

References dmutex_, g_multi_instance, mutex_, and ref_count_.

91  {
92  if (!g_multi_instance) {
93  mutex_.unlock_shared();
94  } else {
95  dmutex_->unlock_shared();
96  }
97  ref_count_.fetch_sub(1u);
98 }
MutexTypeBase mutex_
Definition: LockMgrImpl.h:55
bool g_multi_instance
Definition: heavyai_locks.h:22
std::unique_ptr< heavyai::DistributedSharedMutex > dmutex_
Definition: LockMgrImpl.h:56
std::atomic< size_t > ref_count_
Definition: LockMgrImpl.h:54

Member Data Documentation

std::unique_ptr<heavyai::DistributedSharedMutex> lockmgr::MutexTracker::dmutex_
private

Definition at line 56 of file LockMgrImpl.h.

Referenced by lock(), lock_shared(), try_lock(), try_lock_shared(), unlock(), and unlock_shared().

MutexTypeBase lockmgr::MutexTracker::mutex_
private

Definition at line 55 of file LockMgrImpl.h.

Referenced by lock(), lock_shared(), try_lock(), try_lock_shared(), unlock(), and unlock_shared().

std::atomic<size_t> lockmgr::MutexTracker::ref_count_
private

The documentation for this class was generated from the following files: