From 4eb03ad017c28a705fa7509fea92331ec4d48d29 Mon Sep 17 00:00:00 2001 From: q66 Date: Sat, 23 Jan 2016 22:38:30 +0000 Subject: [PATCH] lock fixes --- ostd/internal/mutex.hh | 9 ++++++++- ostd/thread.hh | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ostd/internal/mutex.hh b/ostd/internal/mutex.hh index 229e910..64e1ca5 100644 --- a/ostd/internal/mutex.hh +++ b/ostd/internal/mutex.hh @@ -86,7 +86,7 @@ struct UniqueLock { UniqueLock(): p_mtx(nullptr), p_owns(false) {} explicit UniqueLock(MutexType &m): p_mtx(&m), p_owns(true) { - m->lock(); + m.lock(); } UniqueLock(MutexType &m, DeferLock): p_mtx(&m), p_owns(false) {} @@ -139,6 +139,13 @@ struct UniqueLock { return ret; } + bool unlock() { + if (!p_mtx || p_owns) return false; + bool ret = p_mtx->unlock(); + if (ret) p_owns = false; + return ret; + } + void swap(UniqueLock &u) { detail::swap_adl(p_mtx, u.p_mtx); detail::swap_adl(p_owns, u.p_owns); diff --git a/ostd/thread.hh b/ostd/thread.hh index ed73a69..63da94e 100644 --- a/ostd/thread.hh +++ b/ostd/thread.hh @@ -71,6 +71,10 @@ namespace this_thread { inline void yield() { thrd_yield(); } + + inline void exit() { + thrd_exit(0); + } } namespace detail {