lock fixes

master
Daniel Kolesa 2016-01-23 22:38:30 +00:00
parent 98eeb765fd
commit 4eb03ad017
2 changed files with 12 additions and 1 deletions

View File

@ -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);

View File

@ -71,6 +71,10 @@ namespace this_thread {
inline void yield() {
thrd_yield();
}
inline void exit() {
thrd_exit(0);
}
}
namespace detail {