23 #include <type_traits>
46 const auto stored_ref_count =
ref_count_.fetch_sub(1u);
47 CHECK_GE(stored_ref_count,
size_t(1));
57 template <
typename LOCK>
72 other.mutex_ =
nullptr;
96 template <
typename T,
typename LOCK>
110 const std::string& tableName);
112 template <
typename LOCK_TYPE,
typename LOCK_MGR_TYPE>
114 auto& table_lock_mgr = LOCK_MGR_TYPE::instance();
115 return LOCK_TYPE(table_lock_mgr.getTableMutex(chunk_key));
118 template <
typename LOCK_TYPE,
typename LOCK_MGR_TYPE>
120 const std::string& table_name) {
123 auto& table_lock_mgr = LOCK_MGR_TYPE::instance();
124 return LOCK_TYPE(table_lock_mgr.getTableMutex(chunk_key));
133 std::lock_guard<std::mutex> access_map_lock(
map_mutex_);
136 table_mutex_map_.insert(std::make_pair(table_key, std::make_unique<MutexType>()));
138 return mutex_it->second.get();
144 std::set<ChunkKey> ret;
145 std::lock_guard<std::mutex> access_map_lock(
map_mutex_);
147 if (kv.second->isAcquired()) {
148 ret.insert(kv.first);
156 const std::string& table_name) {
157 return helpers::getLockForTableImpl<WriteLock, T>(
cat, table_name);
160 auto& table_lock_mgr = T::instance();
161 return WriteLock(table_lock_mgr.getTableMutex(table_key));
165 const std::string& table_name) {
166 return helpers::getLockForTableImpl<ReadLock, T>(
cat, table_name);
169 auto& table_lock_mgr = T::instance();
170 return ReadLock(table_lock_mgr.getTableMutex(table_key));
180 template <
typename T>
181 std::ostream& operator<<(std::ostream& os, const TableLockMgrImpl<T>& lock_mgr) {
182 for (
const auto& table_key : lock_mgr.getLockedTables()) {
183 for (
const auto& k : table_key) {
std::vector< int > ChunkKey
static ReadLock getReadLockForTable(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
mapd_shared_mutex MutexTypeBase
class for a per-database catalog. also includes metadata for the current database and the current use...
static WriteLock getWriteLockForTable(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
std::map< ChunkKey, std::unique_ptr< MutexType > > table_mutex_map_
virtual ~AbstractLockContainer()
mapd_shared_lock< MutexTypeBase > ReadLockBase
std::set< ChunkKey > getLockedTables() const
static WriteLock getWriteLockForTable(const ChunkKey table_key)
LOCK_TYPE getLockForKeyImpl(const ChunkKey &chunk_key)
T operator()() const final
This file contains the class specification and related data structures for Catalog.
TrackedRefLock< WriteLockBase > WriteLock
TrackedRefLock< ReadLockBase > ReadLock
virtual T operator()() const =0
std::shared_timed_mutex mapd_shared_mutex
static ReadLock getReadLockForTable(const ChunkKey table_key)
mapd_unique_lock< MutexTypeBase > WriteLockBase
ChunkKey chunk_key_for_table(const Catalog_Namespace::Catalog &cat, const std::string &tableName)
TrackedRefLock(MutexTracker *m)
LOCK_TYPE getLockForTableImpl(const Catalog_Namespace::Catalog &cat, const std::string &table_name)
TrackedRefLock(TrackedRefLock &&other)
std::atomic< size_t > ref_count_
TrackedRefLock & operator=(const TrackedRefLock &)=delete
MutexType * getTableMutex(const ChunkKey table_key)
LockContainerImpl(T obj, LOCK &&lock)
MutexTypeBase & acquire()