Skip to content

Commit

Permalink
Merge pull request ClickHouse#3204 from CurtizJ/CLICKHOUSE-3527
Browse files Browse the repository at this point in the history
Better code in ClickHouse#3101.
  • Loading branch information
alexey-milovidov authored Sep 24, 2018
2 parents 17b8e20 + d0ed96a commit 002331b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions dbms/src/Interpreters/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
}


Expand Down
4 changes: 2 additions & 2 deletions dbms/src/Interpreters/Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,13 +481,13 @@ class DDLGuard
/// 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;
};

Expand Down

0 comments on commit 002331b

Please sign in to comment.