mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
Merge pull request #3204 from CurtizJ/CLICKHOUSE-3527
Better code in #3101.
This commit is contained in:
commit
002331be1b
@ -897,18 +897,18 @@ StoragePtr Context::executeTableFunction(const ASTPtr & table_expression)
|
||||
}
|
||||
|
||||
|
||||
DDLGuard::DDLGuard(Map & map_, std::mutex & guards_mutex_, std::unique_lock<std::mutex> && lock, const String & elem)
|
||||
: map(map_), guards_mutex(guards_mutex_)
|
||||
DDLGuard::DDLGuard(Map & map_, std::unique_lock<std::mutex> guards_lock_, const String & elem)
|
||||
: map(map_), guards_lock(std::move(guards_lock_))
|
||||
{
|
||||
it = map.emplace(elem, Entry{std::make_unique<std::mutex>(), 0}).first;
|
||||
++it->second.counter;
|
||||
lock.unlock();
|
||||
guards_lock.unlock();
|
||||
table_lock = std::unique_lock<std::mutex>(*it->second.mutex);
|
||||
}
|
||||
|
||||
DDLGuard::~DDLGuard()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(guards_mutex);
|
||||
guards_lock.lock();
|
||||
--it->second.counter;
|
||||
if (!it->second.counter)
|
||||
{
|
||||
@ -920,7 +920,7 @@ DDLGuard::~DDLGuard()
|
||||
std::unique_ptr<DDLGuard> Context::getDDLGuard(const String & database, const String & table) const
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(shared->ddl_guards_mutex);
|
||||
return std::make_unique<DDLGuard>(shared->ddl_guards[database], shared->ddl_guards_mutex, std::move(lock), table);
|
||||
return std::make_unique<DDLGuard>(shared->ddl_guards[database], std::move(lock), table);
|
||||
}
|
||||
|
||||
|
||||
|
@ -481,13 +481,13 @@ public:
|
||||
/// NOTE: using std::map here (and not std::unordered_map) to avoid iterator invalidation on insertion.
|
||||
using Map = std::map<String, Entry>;
|
||||
|
||||
DDLGuard(Map & map_, std::mutex & guards_mutex_, std::unique_lock<std::mutex> && guards_lock, const String & elem);
|
||||
DDLGuard(Map & map_, std::unique_lock<std::mutex> guards_lock_, const String & elem);
|
||||
~DDLGuard();
|
||||
|
||||
private:
|
||||
Map & map;
|
||||
Map::iterator it;
|
||||
std::mutex & guards_mutex;
|
||||
std::unique_lock<std::mutex> guards_lock;
|
||||
std::unique_lock<std::mutex> table_lock;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user