Skip to content

Commit

Permalink
Make CondVar non-copyable, non-moveable (#1426)
Browse files Browse the repository at this point in the history
This makes it consistent with std::condition_variable.

Found using cppcheck:

common/src/dthread.h:114:4: warning: Class 'CondVar' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s). [noCopyConstructor]
   mutex = new mutex_t;
   ^
common/src/dthread.h:114:4: warning: Class 'CondVar' does not have a operator= which is recommended since it has dynamic memory/resource allocation(s). [noOperatorEq]
   mutex = new mutex_t;
  • Loading branch information
hainest committed May 9, 2023
1 parent 45614d7 commit e5409c4
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions common/src/dthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ class PC_EXPORT CondVar {
}
~CondVar() { if(created_mutex) delete mutex; }

CondVar(CondVar const&) = delete;
CondVar& operator=(CondVar const&) = delete;
CondVar(CondVar &&) = delete;
CondVar& operator=(CondVar &&rhs) = delete;

void unlock() { mutex->unlock(); }
bool trylock() { return mutex->try_lock(); }
void lock() { mutex->lock(); }
Expand Down

0 comments on commit e5409c4

Please sign in to comment.