Skip to content

Commit b17355f

Browse files
committed
mstd_mutex: Add missing Chrono bits
1 parent f0ee31f commit b17355f

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

platform/cxxsupport/mstd_mutex

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646

4747
#include <mstd_utility>
4848
#include <mstd_functional>
49+
#include <mstd_tuple>
50+
#include <chrono>
4951

5052
#include "mbed_atomic.h"
5153
#include "mbed_assert.h"
@@ -105,12 +107,10 @@ public:
105107
unique_lock(mutex_type &m, defer_lock_t) noexcept : pm(&m), owns(false) { }
106108
unique_lock(mutex_type &m, try_to_lock_t) : pm(&m), owns(m.try_lock()) { }
107109
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
109110
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)) { }
111112
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)) { }
114114
~unique_lock() { if (owns) pm->unlock(); }
115115

116116
unique_lock(const unique_lock &) = delete;
@@ -141,19 +141,17 @@ public:
141141
return owns = pm->try_lock();
142142
}
143143

144-
#if 0 // disabled until we have functional mstd::chrono for all toolchains
145144
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) {
147146
MBED_ASSERT(!owns);
148147
return owns = pm->try_lock_until(abs_time);
149148
}
150149

151150
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) {
153152
MBED_ASSERT(!owns);
154153
return owns = pm->try_lock_for(rel_time);
155154
}
156-
#endif
157155

158156
void unlock() {
159157
MBED_ASSERT(owns);
@@ -313,9 +311,8 @@ using std::scoped_lock;
313311
// [thread.lock.scoped]
314312
// 2+ locks - use std::lock
315313
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;
319316
static void ignore(...) { }
320317
public:
321318
explicit scoped_lock(MutexTypes &... m) : pm(tie(m...)) { mstd::lock(m...); }
@@ -324,10 +321,7 @@ public:
324321

325322
scoped_lock(const scoped_lock &) = delete;
326323
scoped_lock &operator=(const scoped_lock &) = delete;
327-
}
328-
#else
329-
;
330-
#endif
324+
};
331325

332326
// 0 locks - no-op
333327
template <>

platform/cxxsupport/mstd_tuple

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ using std::make_tuple;
4141
using std::forward_as_tuple;
4242
using std::tie;
4343
using std::tuple_cat;
44+
using std::tuple_size;
45+
using std::tuple_element;
46+
using std::tuple_element_t;
47+
using std::get;
4448

4549
// [tuple.apply]
4650
#if __cpp_lib_apply >= 201603
@@ -84,11 +88,6 @@ T make_from_tuple(Tuple&& t)
8488
}
8589
#endif
8690

87-
using std::tuple_size;
88-
using std::tuple_element;
89-
using std::tuple_element_t;
90-
using std::get;
91-
9291
} // namespace mstd
9392

9493
#endif // MSTD_TUPLE_

0 commit comments

Comments
 (0)