-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStdMutex.cpp
54 lines (43 loc) · 835 Bytes
/
StdMutex.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "StdMutex.h"
namespace BaseLib {
StdMutex::StdMutex(MutexPolicy )
: mutex_(std::make_shared<std::timed_mutex>())
{ }
StdMutex::StdMutex(const StdMutex& other)
: mutex_(other.mutex_)
{ }
StdMutex::~StdMutex()
{ }
StdMutex& StdMutex::operator=(const StdMutex& )
{
return *this;
}
void StdMutex::lock()
{
mutex_->lock();
}
void StdMutex::unlock()
{
mutex_->unlock();
}
bool StdMutex::tryLock(int64 msecs)
{
if(msecs <= 0)
{
return mutex_->try_lock();
}
else
{
std::chrono::duration<int64, std::milli> duration(msecs);
return mutex_->try_lock_for(duration);
}
}
bool StdMutex::tryLock(Duration duration)
{
return mutex_->try_lock_for(duration);
}
bool StdMutex::tryLockUntil(Timestamp timestamp)
{
return mutex_->try_lock_until(timestamp);
}
}