genode/repos/base/include/base/mutex.h
Alexander Boettcher 00f69bc70d 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
2020-02-20 12:11:22 +01:00

47 lines
787 B
C++

/*
* \brief Mutex primitives
* \author Alexander Boettcher
* \date 2020-01-24
*/
/*
* Copyright (C) 2020 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU Affero General Public License version 3.
*/
#ifndef _INCLUDE__BASE__MUTEX_H_
#define _INCLUDE__BASE__MUTEX_H_
#include <base/lock.h>
#include <util/noncopyable.h>
namespace Genode { class Mutex; }
class Genode::Mutex : Noncopyable
{
private:
Lock _lock { };
public:
explicit Mutex() { }
void acquire();
void release();
class Guard
{
private:
Mutex &_mutex;
public:
explicit Guard(Mutex &mutex) : _mutex(mutex) { _mutex.acquire(); }
~Guard() { _mutex.release(); }
};
};
#endif /* _INCLUDE__BASE__MUTEX_H_ */