@@ -41,7 +41,8 @@ Mutex::Mutex(const char *name)
41
41
void Mutex::constructor (const char *name)
42
42
{
43
43
memset (&_obj_mem, 0 , sizeof (_obj_mem));
44
- osMutexAttr_t attr = { 0 };
44
+ osMutexAttr_t attr =
45
+ { 0 };
45
46
attr.name = name ? name : " aplication_unnamed_mutex" ;
46
47
attr.cb_mem = &_obj_mem;
47
48
attr.cb_size = sizeof (_obj_mem);
@@ -50,7 +51,8 @@ void Mutex::constructor(const char *name)
50
51
MBED_ASSERT (_id);
51
52
}
52
53
53
- void Mutex::lock (void ) {
54
+ void Mutex::lock (void )
55
+ {
54
56
osStatus status = osMutexAcquire (_id, osWaitForever);
55
57
if (osOK == status) {
56
58
_count++;
@@ -59,7 +61,8 @@ void Mutex::lock(void) {
59
61
MBED_ASSERT (status == osOK);
60
62
}
61
63
62
- osStatus Mutex::lock (uint32_t millisec) {
64
+ osStatus Mutex::lock (uint32_t millisec)
65
+ {
63
66
osStatus status = osMutexAcquire (_id, millisec);
64
67
if (osOK == status) {
65
68
_count++;
@@ -72,11 +75,13 @@ osStatus Mutex::lock(uint32_t millisec) {
72
75
return status;
73
76
}
74
77
75
- bool Mutex::trylock () {
78
+ bool Mutex::trylock ()
79
+ {
76
80
return trylock_for (0 );
77
81
}
78
82
79
- bool Mutex::trylock_for (uint32_t millisec) {
83
+ bool Mutex::trylock_for (uint32_t millisec)
84
+ {
80
85
osStatus status = osMutexAcquire (_id, millisec);
81
86
if (status == osOK) {
82
87
return true ;
@@ -89,7 +94,8 @@ bool Mutex::trylock_for(uint32_t millisec) {
89
94
return false ;
90
95
}
91
96
92
- bool Mutex::trylock_until (uint64_t millisec) {
97
+ bool Mutex::trylock_until (uint64_t millisec)
98
+ {
93
99
uint64_t now = Kernel::get_ms_count ();
94
100
95
101
if (now >= millisec) {
@@ -102,16 +108,19 @@ bool Mutex::trylock_until(uint64_t millisec) {
102
108
}
103
109
}
104
110
105
- osStatus Mutex::unlock () {
111
+ osStatus Mutex::unlock ()
112
+ {
106
113
_count--;
107
114
return osMutexRelease (_id);
108
115
}
109
116
110
- osThreadId Mutex::get_owner () {
117
+ osThreadId Mutex::get_owner ()
118
+ {
111
119
return osMutexGetOwner (_id);
112
120
}
113
121
114
- Mutex::~Mutex () {
122
+ Mutex::~Mutex ()
123
+ {
115
124
osMutexDelete (_id);
116
125
}
117
126
0 commit comments