base: add mutex as derivate of lock

The mutex class is more restrictive in usage compared to
Genode::Lock.

- At initialiation time it is ever unlocked.
- No thread is permitted to lock twice. Warn about it
  in case it happens.
- Only the lock onwer is permitted to unlock the mutex.
  Warn about it and don't unlock the mutex in case it happens.

Issue #3612
This commit is contained in:
Alexander Boettcher
2020-01-24 13:46:09 +01:00
committed by Christian Helmuth
parent d1609e771a
commit 00f69bc70d
15 changed files with 133 additions and 16 deletions

View File

@@ -12,6 +12,7 @@
*/
#include <base/lock.h>
#include <base/mutex.h>
#include <hw/assert.h>
Genode::Cancelable_lock::Cancelable_lock(Genode::Cancelable_lock::State state)
@@ -30,3 +31,13 @@ void Genode::Cancelable_lock::lock()
assert(_state == UNLOCKED);
_state = LOCKED;
}
void Genode::Mutex::acquire()
{
_lock.lock();
}
void Genode::Mutex::release()
{
_lock.unlock();
}

View File

@@ -62,7 +62,7 @@ thread_check_stopped_and_restart(Genode::Thread * const t)
/**
* Pause execution of current thread
*/
static inline void thread_stop_myself() { Kernel::stop_thread(); }
static inline void thread_stop_myself(Genode::Thread *) { Kernel::stop_thread(); }
#endif /* _INCLUDE__BASE__INTERNAL__LOCK_HELPER_H_ */