46
46
47
47
#include <mstd_utility>
48
48
#include <mstd_functional>
49
+ #include <mstd_tuple>
50
+ #include <chrono>
49
51
50
52
#include "mbed_atomic.h"
51
53
#include "mbed_assert.h"
@@ -105,12 +107,10 @@ public:
105
107
unique_lock(mutex_type &m, defer_lock_t) noexcept : pm(&m), owns(false) { }
106
108
unique_lock(mutex_type &m, try_to_lock_t) : pm(&m), owns(m.try_lock()) { }
107
109
unique_lock(mutex_type &m, adopt_lock_t) : pm(&m), owns(true) { }
108
- #if 0 // disabled until we have functional mstd::chrono for all toolchains
109
110
template <class Clock, class Duration>
110
- unique_lock(mutex_type &m, const chrono::time_point<Clock, Duration> &abs_time) : pm(&m), owns(m.try_lock_until(abs_time)) { }
111
+ unique_lock(mutex_type &m, const std:: chrono::time_point<Clock, Duration> &abs_time) : pm(&m), owns(m.try_lock_until(abs_time)) { }
111
112
template <class Rep, class Period>
112
- unique_lock(mutex_type &m, const chrono::duration<Rep, Period> &rel_time) : pm(&m), owns(m.try_lock_for(rel_time)) { }
113
- #endif
113
+ unique_lock(mutex_type &m, const std::chrono::duration<Rep, Period> &rel_time) : pm(&m), owns(m.try_lock_for(rel_time)) { }
114
114
~unique_lock() { if (owns) pm->unlock(); }
115
115
116
116
unique_lock(const unique_lock &) = delete;
@@ -141,19 +141,17 @@ public:
141
141
return owns = pm->try_lock();
142
142
}
143
143
144
- #if 0 // disabled until we have functional mstd::chrono for all toolchains
145
144
template <class Clock, class Duration>
146
- bool try_lock_until(const chrono::time_point<Clock, Duration> &abs_time) {
145
+ bool try_lock_until(const std:: chrono::time_point<Clock, Duration> &abs_time) {
147
146
MBED_ASSERT(!owns);
148
147
return owns = pm->try_lock_until(abs_time);
149
148
}
150
149
151
150
template <class Rep, class Period>
152
- bool try_lock_for(const chrono::duration<Rep, Period> &rel_time) {
151
+ bool try_lock_for(const std:: chrono::duration<Rep, Period> &rel_time) {
153
152
MBED_ASSERT(!owns);
154
153
return owns = pm->try_lock_for(rel_time);
155
154
}
156
- #endif
157
155
158
156
void unlock() {
159
157
MBED_ASSERT(owns);
@@ -313,9 +311,8 @@ using std::scoped_lock;
313
311
// [thread.lock.scoped]
314
312
// 2+ locks - use std::lock
315
313
template <class... MutexTypes>
316
- class scoped_lock
317
- #if 0 // no definition yet - needs tuple
318
- tuple<MutexTypes &...> pm;
314
+ class scoped_lock {
315
+ mstd::tuple<MutexTypes &...> pm;
319
316
static void ignore(...) { }
320
317
public:
321
318
explicit scoped_lock(MutexTypes &... m) : pm(tie(m...)) { mstd::lock(m...); }
@@ -324,10 +321,7 @@ public:
324
321
325
322
scoped_lock(const scoped_lock &) = delete;
326
323
scoped_lock &operator=(const scoped_lock &) = delete;
327
- }
328
- #else
329
- ;
330
- #endif
324
+ };
331
325
332
326
// 0 locks - no-op
333
327
template <>
0 commit comments