| 1 |
/****************************************************************************** |
| 2 |
This source file is part of the Avogadro project. |
| 3 |
This source code is released under the 3-Clause BSD License, (see "LICENSE"). |
| 4 |
******************************************************************************/ |
| 5 |
|
| 6 |
#include "mutex.h" |
| 7 |
|
| 8 |
#include <mutex> |
| 9 |
|
| 10 |
namespace Avogadro::Core { |
| 11 |
|
| 12 |
using std::mutex; |
| 13 |
|
| 14 |
class Mutex::PIMPL |
| 15 |
{ |
| 16 |
public: |
| 17 |
PIMPL() {} |
| 18 |
|
| 19 |
mutex lock; |
| 20 |
}; |
| 21 |
|
| 22 |
Mutex::Mutex() : d(new PIMPL) {} |
| 23 |
|
| 24 |
Mutex::~Mutex() |
| 25 |
{ |
| 26 |
delete d; |
| 27 |
} |
| 28 |
|
| 29 |
void Mutex::lock() |
| 30 |
{ |
| 31 |
d->lock.lock(); |
| 32 |
} |
| 33 |
|
| 34 |
bool Mutex::tryLock() |
| 35 |
{ |
| 36 |
return d->lock.try_lock(); |
| 37 |
} |
| 38 |
|
| 39 |
void Mutex::unlock() |
| 40 |
{ |
| 41 |
d->lock.unlock(); |
| 42 |
} |
| 43 |
} // namespace Avogadro::Core |