dde_rump: use Mutex/Blockade

Issue #3805
This commit is contained in:
Alexander Boettcher 2020-07-06 14:23:38 +02:00 committed by Norman Feske
parent 5516dbcb1f
commit 9a8a42e819
4 changed files with 35 additions and 35 deletions

View File

@ -81,13 +81,13 @@ class Hard_context_registry : public Genode::Avl_tree<Hard_context>
{
private:
Genode::Lock lock;
Genode::Mutex mutex;
public:
Hard_context *find(Genode::Thread const *t)
{
Genode::Lock::Guard g(lock);
Genode::Mutex::Guard guard(mutex);
if (!first())
return nullptr;
@ -96,13 +96,13 @@ class Hard_context_registry : public Genode::Avl_tree<Hard_context>
void insert(Hard_context *h)
{
Genode::Lock::Guard g(lock);
Genode::Mutex::Guard guard(mutex);
Avl_tree::insert(h);
}
void remove(Hard_context *h)
{
Genode::Lock::Guard g(lock);
Genode::Mutex::Guard guard(mutex);
Avl_tree::remove(h);
}

View File

@ -264,9 +264,9 @@ struct Allocator_policy
typedef Allocator::Fap<MAX_VIRTUAL_MEMORY, Allocator_policy> Rump_alloc;
static Genode::Lock & alloc_lock()
static Genode::Mutex & alloc_mutex()
{
static Genode::Lock inst;
static Genode::Mutex inst { };
return inst;
}
@ -280,7 +280,7 @@ static Rump_alloc* allocator()
int rumpuser_malloc(size_t len, int alignment, void **memp)
{
Genode::Lock::Guard guard(alloc_lock());
Genode::Mutex::Guard guard(alloc_mutex());
int align = alignment ? Genode::log2(alignment) : 0;
*memp = allocator()->alloc(len, align);
@ -295,7 +295,7 @@ int rumpuser_malloc(size_t len, int alignment, void **memp)
void rumpuser_free(void *mem, size_t len)
{
Genode::Lock::Guard guard(alloc_lock());
Genode::Mutex::Guard guard(alloc_mutex());
allocator()->free(mem, len);

View File

@ -32,7 +32,7 @@ class Backend
Genode::Allocator_avl _alloc { &Rump::env().heap() };
Block::Connection<> _session { Rump::env().env(), &_alloc };
Block::Session::Info _info { _session.info() };
Genode::Lock _session_lock;
Genode::Mutex _session_mutex;
void _sync()
{
@ -51,7 +51,7 @@ class Backend
void sync()
{
Genode::Lock::Guard guard(_session_lock);
Genode::Mutex::Guard guard(_session_mutex);
_sync();
}
@ -59,7 +59,7 @@ class Backend
{
using namespace Block;
Genode::Lock::Guard guard(_session_lock);
Genode::Mutex::Guard guard(_session_mutex);
Packet_descriptor::Opcode opcode;
opcode = op & RUMPUSER_BIO_WRITE ? Packet_descriptor::WRITE :

View File

@ -15,7 +15,7 @@
extern "C" {
#include <sys/cdefs.h>
}
#include <base/lock.h>
#include <base/mutex.h>
#include <util/fifo.h>
#include <rump/env.h>
@ -36,15 +36,15 @@ struct rumpuser_mtx
{
struct Applicant : Genode::Fifo<Applicant>::Element
{
Genode::Lock lock { Genode::Lock::LOCKED };
Genode::Blockade blockade { };
void block() { lock.lock(); }
void wake_up() { lock.unlock(); }
void block() { blockade.block(); }
void wake_up() { blockade.wakeup(); }
};
Genode::Fifo<Applicant> fifo;
bool occupied = false;
Genode::Lock meta_lock;
Genode::Mutex meta_lock;
struct lwp *owner = nullptr;
int flags;
@ -61,7 +61,7 @@ struct rumpuser_mtx
*/
Applicant applicant;
{
Genode::Lock::Guard guard(meta_lock);
Genode::Mutex::Guard guard(meta_lock);
if (!occupied) {
occupied = true;
@ -89,7 +89,7 @@ struct rumpuser_mtx
void exit()
{
Genode::Lock::Guard guard(meta_lock);
Genode::Mutex::Guard guard(meta_lock);
occupied = false;
@ -213,7 +213,7 @@ struct Cond
{
int num_waiters;
int num_signallers;
Genode::Lock counter_lock;
Genode::Mutex counter_mutex;
Timed_semaphore signal_sem { Rump::env().timeout_ep() };
Genode::Semaphore handshake_sem;
@ -225,9 +225,9 @@ struct Cond
using namespace Genode;
int result = 0;
counter_lock.lock();
counter_mutex.acquire();
num_waiters++;
counter_lock.unlock();
counter_mutex.release();
mutex->exit();
@ -248,7 +248,7 @@ struct Cond
}
}
counter_lock.lock();
counter_mutex.acquire();
if (num_signallers > 0) {
if (result == -2) /* timeout occured */
signal_sem.down();
@ -256,7 +256,7 @@ struct Cond
--num_signallers;
}
num_waiters--;
counter_lock.unlock();
counter_mutex.release();
mutex->enter();
@ -270,30 +270,30 @@ struct Cond
int signal()
{
counter_lock.lock();
counter_mutex.acquire();
if (num_waiters > num_signallers) {
++num_signallers;
signal_sem.up();
counter_lock.unlock();
counter_mutex.release();
handshake_sem.down();
} else
counter_lock.unlock();
counter_mutex.release();
return 0;
}
int broadcast()
{
counter_lock.lock();
counter_mutex.acquire();
if (num_waiters > num_signallers) {
int still_waiting = num_waiters - num_signallers;
num_signallers = num_waiters;
for (int i = 0; i < still_waiting; i++)
signal_sem.up();
counter_lock.unlock();
counter_mutex.release();
for (int i = 0; i < still_waiting; i++)
handshake_sem.down();
} else
counter_lock.unlock();
counter_mutex.release();
return 0;
}
@ -425,8 +425,8 @@ void rumpuser_cv_has_waiters(struct rumpuser_cv *cv, int *nwaiters)
struct Rw_lock {
Genode::Semaphore _lock;
Genode::Lock _inc;
Genode::Lock _write;
Genode::Mutex _inc { };
Genode::Mutex _write { };
int _read;
@ -434,7 +434,7 @@ struct Rw_lock {
bool read_lock(bool try_lock)
{
Genode::Lock::Guard guard(_inc);
Genode::Mutex::Guard guard(_inc);
if (_read > 0) {
_read++;
@ -458,14 +458,14 @@ struct Rw_lock {
void read_unlock()
{
Genode::Lock::Guard guard(_inc);
Genode::Mutex::Guard guard(_inc);
if (--_read == 0)
unlock();
}
bool lock(bool try_lock)
{
Genode::Lock::Guard guard(_write);
Genode::Mutex::Guard guard(_write);
if (_lock.cnt() > 0) {
_lock.down();
return true;
@ -480,7 +480,7 @@ struct Rw_lock {
void unlock()
{
Genode::Lock::Guard guard(_write);
Genode::Mutex::Guard guard(_write);
_lock.up();
}