Skip to content

Commit

Permalink
mstd_mutex: Add missing Chrono bits
Browse files Browse the repository at this point in the history
  • Loading branch information
kjbracey committed Apr 27, 2020
1 parent f0ee31f commit b17355f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
24 changes: 9 additions & 15 deletions platform/cxxsupport/mstd_mutex
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@

#include <mstd_utility>
#include <mstd_functional>
#include <mstd_tuple>
#include <chrono>

#include "mbed_atomic.h"
#include "mbed_assert.h"
Expand Down Expand Up @@ -105,12 +107,10 @@ public:
unique_lock(mutex_type &m, defer_lock_t) noexcept : pm(&m), owns(false) { }
unique_lock(mutex_type &m, try_to_lock_t) : pm(&m), owns(m.try_lock()) { }
unique_lock(mutex_type &m, adopt_lock_t) : pm(&m), owns(true) { }
#if 0 // disabled until we have functional mstd::chrono for all toolchains
template <class Clock, class Duration>
unique_lock(mutex_type &m, const chrono::time_point<Clock, Duration> &abs_time) : pm(&m), owns(m.try_lock_until(abs_time)) { }
unique_lock(mutex_type &m, const std::chrono::time_point<Clock, Duration> &abs_time) : pm(&m), owns(m.try_lock_until(abs_time)) { }
template <class Rep, class Period>
unique_lock(mutex_type &m, const chrono::duration<Rep, Period> &rel_time) : pm(&m), owns(m.try_lock_for(rel_time)) { }
#endif
unique_lock(mutex_type &m, const std::chrono::duration<Rep, Period> &rel_time) : pm(&m), owns(m.try_lock_for(rel_time)) { }
~unique_lock() { if (owns) pm->unlock(); }

unique_lock(const unique_lock &) = delete;
Expand Down Expand Up @@ -141,19 +141,17 @@ public:
return owns = pm->try_lock();
}

#if 0 // disabled until we have functional mstd::chrono for all toolchains
template <class Clock, class Duration>
bool try_lock_until(const chrono::time_point<Clock, Duration> &abs_time) {
bool try_lock_until(const std::chrono::time_point<Clock, Duration> &abs_time) {
MBED_ASSERT(!owns);
return owns = pm->try_lock_until(abs_time);
}

template <class Rep, class Period>
bool try_lock_for(const chrono::duration<Rep, Period> &rel_time) {
bool try_lock_for(const std::chrono::duration<Rep, Period> &rel_time) {
MBED_ASSERT(!owns);
return owns = pm->try_lock_for(rel_time);
}
#endif

void unlock() {
MBED_ASSERT(owns);
Expand Down Expand Up @@ -313,9 +311,8 @@ using std::scoped_lock;
// [thread.lock.scoped]
// 2+ locks - use std::lock
template <class... MutexTypes>
class scoped_lock
#if 0 // no definition yet - needs tuple
tuple<MutexTypes &...> pm;
class scoped_lock {
mstd::tuple<MutexTypes &...> pm;
static void ignore(...) { }
public:
explicit scoped_lock(MutexTypes &... m) : pm(tie(m...)) { mstd::lock(m...); }
Expand All @@ -324,10 +321,7 @@ public:

scoped_lock(const scoped_lock &) = delete;
scoped_lock &operator=(const scoped_lock &) = delete;
}
#else
;
#endif
};

// 0 locks - no-op
template <>
Expand Down
9 changes: 4 additions & 5 deletions platform/cxxsupport/mstd_tuple
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ using std::make_tuple;
using std::forward_as_tuple;
using std::tie;
using std::tuple_cat;
using std::tuple_size;
using std::tuple_element;
using std::tuple_element_t;
using std::get;

// [tuple.apply]
#if __cpp_lib_apply >= 201603
Expand Down Expand Up @@ -84,11 +88,6 @@ T make_from_tuple(Tuple&& t)
}
#endif

using std::tuple_size;
using std::tuple_element;
using std::tuple_element_t;
using std::get;

} // namespace mstd

#endif // MSTD_TUPLE_

0 comments on commit b17355f

Please sign in to comment.