mirror of
https://github.com/genodelabs/genode.git
synced 2025-05-03 09:12:57 +00:00
This patch cleans up the thread API and comes with the following noteworthy changes: - Introduced Cpu_session::Weight type that replaces a formerly used plain integer value to prevent the accidental mix-up of arguments. - The enum definition of Cpu_session::DEFAULT_WEIGHT moved to Cpu_session::Weight::DEFAULT_WEIGHT - New Thread constructor that takes a 'Env &' as first argument. The original constructors are now marked as deprecated. For the common use case where the default 'Weight' and 'Affinity' are used, a shortcut is provided. In the long term, those two constructors should be the only ones to remain. - The former 'Thread<>' class template has been renamed to 'Thread_deprecated'. - The former 'Thread_base' class is now called 'Thread'. - The new 'name()' accessor returns the thread's name as 'Name' object as centrally defined via 'Cpu_session::Name'. It is meant to replace the old-fashioned 'name' method that takes a buffer and size as arguments. - Adaptation of the thread test to the new API Issue #1954
98 lines
1.8 KiB
C++
98 lines
1.8 KiB
C++
/*
|
|
* \brief Basic locking primitive
|
|
* \author Norman Feske
|
|
* \date 2006-07-26
|
|
*/
|
|
|
|
/*
|
|
* Copyright (C) 2006-2013 Genode Labs GmbH
|
|
*
|
|
* 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/blocking.h>
|
|
|
|
namespace Genode {
|
|
|
|
class Thread;
|
|
class Cancelable_lock;
|
|
}
|
|
|
|
|
|
class Genode::Cancelable_lock
|
|
{
|
|
private:
|
|
|
|
class Applicant
|
|
{
|
|
private:
|
|
|
|
Thread *_thread_base;
|
|
Applicant *_to_wake_up;
|
|
|
|
public:
|
|
|
|
explicit Applicant(Thread *thread_base)
|
|
: _thread_base(thread_base), _to_wake_up(0) { }
|
|
|
|
void applicant_to_wake_up(Applicant *to_wake_up) {
|
|
_to_wake_up = to_wake_up; }
|
|
|
|
Applicant *applicant_to_wake_up() { return _to_wake_up; }
|
|
|
|
Thread *thread_base() { return _thread_base; }
|
|
|
|
/**
|
|
* Called from previous lock owner
|
|
*/
|
|
void wake_up();
|
|
|
|
bool operator == (Applicant &a) { return _thread_base == a.thread_base(); }
|
|
bool operator != (Applicant &a) { return _thread_base != a.thread_base(); }
|
|
};
|
|
|
|
/*
|
|
* Note that modifications of the applicants queue must be performed
|
|
* atomically. Hence, we use the additional spinlock here.
|
|
*/
|
|
|
|
volatile int _spinlock_state;
|
|
volatile int _state;
|
|
|
|
Applicant* volatile _last_applicant;
|
|
Applicant _owner;
|
|
|
|
public:
|
|
|
|
enum State { LOCKED, UNLOCKED };
|
|
|
|
/**
|
|
* Constructor
|
|
*/
|
|
explicit Cancelable_lock(State initial = UNLOCKED);
|
|
|
|
/**
|
|
* Try to aquire the lock and block while the lock is not free
|
|
*
|
|
* \throw Genode::Blocking_canceled
|
|
*/
|
|
void lock();
|
|
|
|
/**
|
|
* Release lock
|
|
*/
|
|
void unlock();
|
|
|
|
/**
|
|
* Lock guard
|
|
*/
|
|
typedef Genode::Lock_guard<Cancelable_lock> Guard;
|
|
};
|
|
|
|
#endif /* _INCLUDE__BASE__CANCELABLE_LOCK_H_ */
|