-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmutex.cpp
54 lines (45 loc) · 1.04 KB
/
mutex.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 "mutex.hpp"
#include <cassert>
#include <string_view>
#include <utility>
namespace ThreadX
{
Mutex::Mutex(const InheritMode inheritMode) : Mutex("mutex", inheritMode)
{
}
Mutex::Mutex(const std::string_view name, const InheritMode inheritMode) : Native::TX_MUTEX{}
{
using namespace Native;
[[maybe_unused]] Error error{tx_mutex_create(this, const_cast<char *>(name.data()), std::to_underlying(inheritMode))};
assert(error == Error::success);
}
Mutex::~Mutex()
{
[[maybe_unused]] Error error{tx_mutex_delete(this)};
assert(error == Error::success);
}
Error Mutex::lock()
{
return try_lock_for(TickTimer::waitForever);
}
Error Mutex::try_lock()
{
return try_lock_for(TickTimer::noWait);
}
Error Mutex::unlock()
{
return Error{tx_mutex_put(this)};
}
std::string_view Mutex::name() const
{
return std::string_view{tx_mutex_name};
}
Error Mutex::prioritise()
{
return Error{tx_mutex_prioritize(this)};
}
uintptr_t Mutex::lockingThreadID() const
{
return uintptr_t(tx_mutex_owner);
}
} // namespace ThreadX