genode/repos/base/include/base/lock.h

45 lines
763 B
C
Raw Normal View History

2011-12-22 16:19:25 +01:00
/*
* \brief Locking primitives
* \author Norman Feske
* \date 2006-07-26
*/
/*
2013-01-10 21:44:47 +01:00
* Copyright (C) 2006-2013 Genode Labs GmbH
2011-12-22 16:19:25 +01:00
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
#ifndef _INCLUDE__BASE__LOCK_H_
#define _INCLUDE__BASE__LOCK_H_
#include <base/cancelable_lock.h>
namespace Genode { class Lock; }
2015-03-27 14:27:55 +01:00
struct Genode::Lock : Cancelable_lock
{
2015-03-27 14:27:55 +01:00
/**
* Constructor
*/
explicit Lock(State initial = UNLOCKED) : Cancelable_lock(initial) { }
void lock()
{
while (1)
try {
Cancelable_lock::lock();
return;
} catch (Blocking_canceled) { }
}
/**
* Lock guard
*/
typedef Lock_guard<Lock> Guard;
};
2011-12-22 16:19:25 +01:00
#endif /* _INCLUDE__BASE__LOCK_H_ */