core: use Mutex/Blockade

Issue #3612
This commit is contained in:
Alexander Boettcher
2020-02-18 15:29:47 +01:00
committed by Christian Helmuth
parent 85a1f91f59
commit e87d60ddf7
48 changed files with 218 additions and 232 deletions

View File

@ -27,8 +27,8 @@ class Genode::Irq_object : public Thread_deprecated<4096>
private:
Genode::Signal_context_capability _sig_cap;
Genode::Lock _sync_ack;
Genode::Lock _sync_bootup;
Genode::Blockade _sync_ack { };
Genode::Blockade _sync_bootup { };
unsigned const _irq;
int _fd;

View File

@ -45,8 +45,6 @@ Genode::Irq_session::Info Genode::Irq_session_component::info()
Genode::Irq_object::Irq_object(unsigned irq) :
Thread_deprecated<4096>("irq"),
_sig_cap(Signal_context_capability()),
_sync_ack(Lock::LOCKED),
_sync_bootup(Lock::LOCKED),
_irq(irq),
_fd(-1)
{

View File

@ -53,8 +53,6 @@ Genode::Irq_session::Info Genode::Irq_session_component::info()
Genode::Irq_object::Irq_object(unsigned irq) :
Thread_deprecated<4096>("irq"),
_sig_cap(Signal_context_capability()),
_sync_ack(Lock::LOCKED),
_sync_bootup(Lock::LOCKED),
_irq(irq),
_fd(-1)
{ }
@ -82,8 +80,8 @@ void Genode::Irq_object::entry()
error("failed to register IRQ ", _irq);
}
_sync_bootup.unlock();
_sync_ack.lock();
_sync_bootup.wakeup();
_sync_ack.block();
while (true) {
@ -97,19 +95,19 @@ void Genode::Irq_object::entry()
Genode::Signal_transmitter(_sig_cap).submit(1);
_sync_ack.lock();
_sync_ack.block();
}
}
void Genode::Irq_object::ack_irq()
{
_sync_ack.unlock();
_sync_ack.wakeup();
}
void Genode::Irq_object::start()
{
Genode::Thread::start();
_sync_bootup.lock();
_sync_bootup.block();
}
void Genode::Irq_object::sigh(Signal_context_capability cap)

View File

@ -36,10 +36,10 @@ extern int main_thread_futex_counter;
static void empty_signal_handler(int) { }
static Lock &startup_lock()
static Blockade &startup_lock()
{
static Lock lock(Lock::LOCKED);
return lock;
static Blockade blockade;
return blockade;
}
@ -75,7 +75,7 @@ void Thread::_thread_start()
}
/* wakeup 'start' function */
startup_lock().unlock();
startup_lock().wakeup();
thread->entry();
@ -140,8 +140,8 @@ void Thread::_deinit_platform_thread()
void Thread::start()
{
/* synchronize calls of the 'start' function */
static Lock lock;
Lock::Guard guard(lock);
static Mutex mutex;
Mutex::Guard guard(mutex);
_init_cpu_session_and_trace_control();
@ -161,7 +161,7 @@ void Thread::start()
native_thread().pid = lx_getpid();
/* wait until the 'thread_start' function got entered */
startup_lock().lock();
startup_lock().block();
}

View File

@ -250,26 +250,21 @@ namespace Genode {
{
private:
/**
* Lock with the initial state set to LOCKED
*/
struct Barrier : Lock { Barrier() : Lock(Lock::LOCKED) { } };
/**
* Used to block the constructor until the new thread has initialized
* 'id'
*/
Barrier _construct_lock { };
Blockade _construct_lock { };
/**
* Used to block the new thread until 'start' is called
*/
Barrier _start_lock { };
Blockade _start_lock { };
/**
* Used to block the 'join()' function until the 'entry()' is done
*/
Barrier _join_lock { };
Blockade _join_lock { };
public:
@ -278,32 +273,32 @@ namespace Genode {
void wait_for_construction() override
{
_construct_lock.lock();
_construct_lock.block();
}
void constructed() override
{
_construct_lock.unlock();
_construct_lock.wakeup();
}
void wait_for_start() override
{
_start_lock.lock();
_start_lock.block();
}
void started() override
{
_start_lock.unlock();
_start_lock.wakeup();
}
void wait_for_join() override
{
_join_lock.lock();
_join_lock.block();
}
void joined() override
{
_join_lock.unlock();
_join_lock.wakeup();
}
};

View File

@ -19,9 +19,9 @@ enum { STACK_SIZE = 4096 };
struct Thread : Genode::Thread_deprecated<STACK_SIZE>
{
Genode::Lock &_barrier;
Genode::Blockade &_barrier;
Thread(Genode::Lock &barrier)
Thread(Genode::Blockade &barrier)
: Genode::Thread_deprecated<STACK_SIZE>("stat"), _barrier(barrier) { start(); }
void entry() override
@ -37,7 +37,7 @@ struct Thread : Genode::Thread_deprecated<STACK_SIZE>
/*
* Let main thread procees
*/
_barrier.unlock();
_barrier.wakeup();
}
};
@ -55,7 +55,7 @@ void Component::construct(Genode::Env &env)
{
Genode::log("--- thread-local errno test ---");
static Genode::Lock barrier(Genode::Lock::LOCKED);
static Genode::Blockade barrier;
int const orig_errno = errno;
@ -65,7 +65,7 @@ void Component::construct(Genode::Env &env)
static Thread thread(barrier);
/* block until the thread performed a 'stat' syscall */
barrier.lock();
barrier.block();
Genode::log("main: after thread completed, errno=", errno);

View File

@ -24,9 +24,9 @@
static Genode::Lock *main_wait_lock()
static Genode::Blockade *main_wait_lock()
{
static Genode::Lock inst(Genode::Lock::LOCKED);
static Genode::Blockade inst;
return &inst;
}
@ -46,7 +46,7 @@ static void *pthread_entry(void *)
Genode::log("second message");
main_wait_lock()->unlock();
main_wait_lock()->wakeup();
return 0;
}
@ -67,7 +67,7 @@ void Component::construct(Genode::Env &env)
pthread_create(&pth, 0, pthread_entry, 0);
/* wait until 'pthread_entry' finished */
main_wait_lock()->lock();
main_wait_lock()->block();
Genode::log("--- finished pthread IPC test ---");
exit_status = 0;

View File

@ -28,7 +28,7 @@ inline int lx_gettimeofday(struct timeval *tv, struct timeval *tz) {
Microseconds Timer::Time_source::max_timeout() const
{
Lock::Guard lock_guard(_lock);
Mutex::Guard mutex_guard(_mutex);
return Microseconds(1000 * 1000);
}