Merge pull request #3204 from CurtizJ/CLICKHOUSE-3527

Better code in #3101.
This commit is contained in:
alexey-milovidov 2018-09-25 00:28:11 +03:00 committed by GitHub
commit 002331be1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -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);
}

View File

@ -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;
};