2011-12-22 15:19:25 +00:00
|
|
|
/*
|
|
|
|
* \brief Basic locking primitive
|
|
|
|
* \author Norman Feske
|
|
|
|
* \date 2006-07-26
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2013-01-10 20:44:47 +00:00
|
|
|
* Copyright (C) 2006-2013 Genode Labs GmbH
|
2011-12-22 15:19:25 +00: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__CANCELABLE_LOCK_H_
|
|
|
|
#define _INCLUDE__BASE__CANCELABLE_LOCK_H_
|
|
|
|
|
|
|
|
#include <base/lock_guard.h>
|
|
|
|
#include <base/native_types.h>
|
|
|
|
#include <base/blocking.h>
|
|
|
|
|
|
|
|
namespace Genode {
|
|
|
|
|
|
|
|
class Cancelable_lock
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
2013-02-13 21:13:47 +00:00
|
|
|
int volatile _lock;
|
2011-12-22 15:19:25 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum State { LOCKED, UNLOCKED };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
Cancelable_lock(State initial = UNLOCKED);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to aquire lock an block while lock is not free
|
|
|
|
*
|
|
|
|
* This function may throw a Genode::Blocking_canceled exception.
|
|
|
|
*/
|
|
|
|
void lock();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Release lock
|
|
|
|
*/
|
|
|
|
void unlock();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lock guard
|
|
|
|
*/
|
|
|
|
typedef Genode::Lock_guard<Cancelable_lock> Guard;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* _INCLUDE__BASE__CANCELABLE_LOCK_H_ */
|