mirror of
https://github.com/genodelabs/genode.git
synced 2024-12-19 05:37:54 +00:00
parent
93ab972ddc
commit
0e6c32f75e
@ -15,7 +15,8 @@
|
||||
#ifndef _LIBC_PLUGIN__FD_ALLOC_H_
|
||||
#define _LIBC_PLUGIN__FD_ALLOC_H_
|
||||
|
||||
#include <base/lock.h>
|
||||
/* Genode includes */
|
||||
#include <base/mutex.h>
|
||||
#include <base/log.h>
|
||||
#include <os/path.h>
|
||||
#include <base/allocator.h>
|
||||
@ -42,7 +43,7 @@ namespace Libc {
|
||||
|
||||
struct File_descriptor
|
||||
{
|
||||
Genode::Lock lock { };
|
||||
Genode::Mutex mutex { };
|
||||
|
||||
typedef Genode::Id_space<File_descriptor> Id_space;
|
||||
Id_space::Element _elem;
|
||||
@ -70,7 +71,7 @@ namespace Libc {
|
||||
{
|
||||
private:
|
||||
|
||||
Genode::Lock _lock;
|
||||
Genode::Mutex _mutex;
|
||||
|
||||
Genode::Allocator &_alloc;
|
||||
|
||||
|
@ -58,7 +58,7 @@ File_descriptor *File_descriptor_allocator::alloc(Plugin *plugin,
|
||||
Plugin_context *context,
|
||||
int libc_fd)
|
||||
{
|
||||
Lock::Guard guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
bool const any_fd = (libc_fd < 0);
|
||||
Id_space::Id id {(unsigned)libc_fd};
|
||||
@ -75,7 +75,7 @@ File_descriptor *File_descriptor_allocator::alloc(Plugin *plugin,
|
||||
|
||||
void File_descriptor_allocator::free(File_descriptor *fdo)
|
||||
{
|
||||
Lock::Guard guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
if (fdo->fd_path)
|
||||
_alloc.free((void *)fdo->fd_path, ::strlen(fdo->fd_path) + 1);
|
||||
@ -94,7 +94,7 @@ void File_descriptor_allocator::preserve(int fd)
|
||||
|
||||
File_descriptor *File_descriptor_allocator::find_by_libc_fd(int libc_fd)
|
||||
{
|
||||
Lock::Guard guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
if (libc_fd < 0)
|
||||
return nullptr;
|
||||
@ -113,7 +113,7 @@ File_descriptor *File_descriptor_allocator::find_by_libc_fd(int libc_fd)
|
||||
|
||||
File_descriptor *File_descriptor_allocator::any_cloexec_libc_fd()
|
||||
{
|
||||
Lock::Guard guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
File_descriptor *result = nullptr;
|
||||
|
||||
@ -127,7 +127,7 @@ File_descriptor *File_descriptor_allocator::any_cloexec_libc_fd()
|
||||
|
||||
int File_descriptor_allocator::any_open_fd()
|
||||
{
|
||||
Lock::Guard guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
int result = -1;
|
||||
_id_space.apply_any<File_descriptor>([&] (File_descriptor &fd) {
|
||||
@ -139,7 +139,7 @@ int File_descriptor_allocator::any_open_fd()
|
||||
|
||||
void File_descriptor_allocator::generate_info(Xml_generator &xml)
|
||||
{
|
||||
Lock::Guard guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
_id_space.for_each<File_descriptor>([&] (File_descriptor &fd) {
|
||||
xml.node("fd", [&] () {
|
||||
|
@ -532,7 +532,7 @@ struct Libc::Kernel final : Vfs::Io_response_handler,
|
||||
/**
|
||||
* Monitor interface
|
||||
*/
|
||||
bool _monitor(Genode::Lock &mutex, Function &fn, uint64_t timeout_ms) override
|
||||
bool _monitor(Mutex &mutex, Function &fn, uint64_t timeout_ms) override
|
||||
{
|
||||
if (_main_context()) {
|
||||
Main_job job { fn, timeout_ms };
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/env.h>
|
||||
#include <base/lock.h>
|
||||
#include <base/mutex.h>
|
||||
#include <timer_session/connection.h>
|
||||
|
||||
namespace Libc { struct Kernel_timer_accessor; }
|
||||
@ -28,9 +28,9 @@ struct Libc::Kernel_timer_accessor : Timer_accessor
|
||||
/*
|
||||
* The '_timer' is constructed by whatever thread (main thread
|
||||
* of pthread) that uses a time-related function first. Hence,
|
||||
* the construction must be protected by a lock.
|
||||
* the construction must be protected by a mutex.
|
||||
*/
|
||||
Lock _lock;
|
||||
Mutex _mutex;
|
||||
|
||||
Constructible<Timer> _timer;
|
||||
|
||||
@ -38,7 +38,7 @@ struct Libc::Kernel_timer_accessor : Timer_accessor
|
||||
|
||||
Timer &timer() override
|
||||
{
|
||||
Lock::Guard guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
if (!_timer.constructed())
|
||||
_timer.construct(_env);
|
||||
|
@ -104,7 +104,7 @@ namespace Libc {
|
||||
_ram = ram, _region_map = rm; }
|
||||
};
|
||||
|
||||
Lock mutable _lock;
|
||||
Mutex mutable _mutex;
|
||||
Dataspace_pool _ds_pool; /* list of dataspaces */
|
||||
Allocator_avl _alloc; /* local allocator */
|
||||
size_t _chunk_size;
|
||||
|
@ -15,7 +15,7 @@
|
||||
#define _LIBC__INTERNAL__MMAP_REGISTRY_H_
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/lock.h>
|
||||
#include <base/mutex.h>
|
||||
#include <base/env.h>
|
||||
#include <base/log.h>
|
||||
#include <libc/allocator.h>
|
||||
@ -57,7 +57,7 @@ class Libc::Mmap_registry
|
||||
|
||||
List<Mmap_registry::Entry> _list;
|
||||
|
||||
Lock mutable _lock;
|
||||
Mutex mutable _mutex;
|
||||
|
||||
/*
|
||||
* Common for both const and non-const lookup functions
|
||||
@ -86,7 +86,7 @@ class Libc::Mmap_registry
|
||||
|
||||
void insert(void *start, size_t len, Plugin *plugin)
|
||||
{
|
||||
Lock::Guard guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
if (_lookup_by_addr_unsynchronized(start)) {
|
||||
warning(__func__, ": mmap region at ", start, " "
|
||||
@ -99,7 +99,7 @@ class Libc::Mmap_registry
|
||||
|
||||
Plugin *lookup_plugin_by_addr(void *start) const
|
||||
{
|
||||
Lock::Guard guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
Entry const * const e = _lookup_by_addr_unsynchronized(start);
|
||||
return e ? e->plugin : 0;
|
||||
@ -107,14 +107,14 @@ class Libc::Mmap_registry
|
||||
|
||||
bool registered(void *start) const
|
||||
{
|
||||
Lock::Guard guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
return _lookup_by_addr_unsynchronized(start) != 0;
|
||||
}
|
||||
|
||||
void remove(void *start)
|
||||
{
|
||||
Lock::Guard guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
Entry *e = _lookup_by_addr_unsynchronized(start);
|
||||
|
||||
|
@ -55,7 +55,7 @@ class Libc::Monitor : Interface
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool _monitor(Genode::Lock &, Function &, uint64_t) = 0;
|
||||
virtual bool _monitor(Mutex &, Function &, uint64_t) = 0;
|
||||
virtual void _charge_monitors() = 0;
|
||||
|
||||
public:
|
||||
@ -70,7 +70,7 @@ class Libc::Monitor : Interface
|
||||
* Returns true if execution completed, false on timeout.
|
||||
*/
|
||||
template <typename FN>
|
||||
bool monitor(Genode::Lock &mutex, FN const &fn, uint64_t timeout_ms = 0)
|
||||
bool monitor(Mutex &mutex, FN const &fn, uint64_t timeout_ms = 0)
|
||||
{
|
||||
struct _Function : Function
|
||||
{
|
||||
@ -118,26 +118,26 @@ struct Libc::Monitor::Pool
|
||||
private:
|
||||
|
||||
Registry<Job> _jobs;
|
||||
Mutex _mutex;
|
||||
|
||||
Lock _mutex;
|
||||
bool _execution_pending { false };
|
||||
|
||||
public:
|
||||
|
||||
void monitor(Genode::Lock &mutex, Job &job)
|
||||
void monitor(Mutex &mutex, Job &job)
|
||||
{
|
||||
Registry<Job>::Element element { _jobs, job };
|
||||
|
||||
mutex.unlock();
|
||||
mutex.release();
|
||||
|
||||
job.wait_for_completion();
|
||||
|
||||
mutex.lock();
|
||||
mutex.acquire();
|
||||
}
|
||||
|
||||
bool charge_monitors()
|
||||
{
|
||||
Lock::Guard guard { _mutex };
|
||||
Mutex::Guard guard { _mutex };
|
||||
|
||||
bool const charged = !_execution_pending;
|
||||
_execution_pending = true;
|
||||
@ -147,7 +147,7 @@ struct Libc::Monitor::Pool
|
||||
void execute_monitors()
|
||||
{
|
||||
{
|
||||
Lock::Guard guard { _mutex };
|
||||
Mutex::Guard guard { _mutex };
|
||||
|
||||
if (!_execution_pending) return;
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#define _LIBC__INTERNAL__PTHREAD_H_
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/blockade.h>
|
||||
#include <libc/allocator.h>
|
||||
#include <libc/component.h>
|
||||
#include <util/reconstructible.h>
|
||||
@ -165,7 +166,7 @@ struct Libc::Pthread : Noncopyable, Thread::Tls::Base
|
||||
bool _exiting = false;
|
||||
|
||||
/*
|
||||
* The join lock is needed because 'Libc::resume_all()' uses a
|
||||
* The join blockade is needed because 'Libc::resume_all()' uses a
|
||||
* 'Signal_transmitter' which holds a reference to a signal context
|
||||
* capability, which needs to be released before the thread can be
|
||||
* destroyed.
|
||||
@ -174,7 +175,7 @@ struct Libc::Pthread : Noncopyable, Thread::Tls::Base
|
||||
* returns when the thread entry function returns, which does not
|
||||
* happen with 'pthread_cancel()'.
|
||||
*/
|
||||
Lock _join_lock { Lock::LOCKED };
|
||||
Genode::Blockade _join_blockade;
|
||||
|
||||
/* return value for 'pthread_join()' */
|
||||
void *_retval = PTHREAD_CANCELED;
|
||||
@ -301,7 +302,7 @@ class Libc::Pthread_blockade : public Blockade, public Timeout_handler
|
||||
{
|
||||
private:
|
||||
|
||||
Lock _blockade { Lock::LOCKED };
|
||||
Genode::Blockade _blockade;
|
||||
Constructible<Timeout> _timeout;
|
||||
|
||||
public:
|
||||
@ -314,12 +315,12 @@ class Libc::Pthread_blockade : public Blockade, public Timeout_handler
|
||||
}
|
||||
}
|
||||
|
||||
void block() override { _blockade.lock(); }
|
||||
void block() override { _blockade.block(); }
|
||||
|
||||
void wakeup() override
|
||||
{
|
||||
_woken_up = true;
|
||||
_blockade.unlock();
|
||||
_blockade.wakeup();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -328,7 +329,7 @@ class Libc::Pthread_blockade : public Blockade, public Timeout_handler
|
||||
void handle_timeout() override
|
||||
{
|
||||
_expired = true;
|
||||
_blockade.unlock();
|
||||
_blockade.wakeup();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -26,7 +26,8 @@ struct Libc::Pthread_pool
|
||||
{
|
||||
struct Pthread : Timeout_handler
|
||||
{
|
||||
Lock lock { Lock::LOCKED };
|
||||
Blockade blockade;
|
||||
|
||||
Pthread *next { nullptr };
|
||||
|
||||
Timer_accessor &_timer_accessor;
|
||||
@ -55,11 +56,11 @@ struct Libc::Pthread_pool
|
||||
|
||||
void handle_timeout() override
|
||||
{
|
||||
lock.unlock();
|
||||
blockade.wakeup();
|
||||
}
|
||||
};
|
||||
|
||||
Lock mutex;
|
||||
Mutex mutex;
|
||||
Pthread *pthreads = nullptr;
|
||||
Timer_accessor &timer_accessor;
|
||||
|
||||
@ -69,27 +70,27 @@ struct Libc::Pthread_pool
|
||||
|
||||
void resume_all()
|
||||
{
|
||||
Lock::Guard g(mutex);
|
||||
Mutex::Guard g(mutex);
|
||||
|
||||
for (Pthread *p = pthreads; p; p = p->next)
|
||||
p->lock.unlock();
|
||||
p->blockade.wakeup();
|
||||
}
|
||||
|
||||
uint64_t suspend_myself(Suspend_functor & check, uint64_t timeout_ms)
|
||||
{
|
||||
Pthread myself { timer_accessor, timeout_ms };
|
||||
{
|
||||
Lock::Guard g(mutex);
|
||||
Mutex::Guard g(mutex);
|
||||
|
||||
myself.next = pthreads;
|
||||
pthreads = &myself;
|
||||
}
|
||||
|
||||
if (check.suspend())
|
||||
myself.lock.lock();
|
||||
myself.blockade.block();
|
||||
|
||||
{
|
||||
Lock::Guard g(mutex);
|
||||
Mutex::Guard g(mutex);
|
||||
|
||||
/* address of pointer to next pthread allows to change the head */
|
||||
for (Pthread **next = &pthreads; *next; next = &(*next)->next) {
|
||||
|
@ -87,7 +87,7 @@ int Libc::Mem_alloc_impl::Dataspace_pool::expand(size_t size, Range_allocator *a
|
||||
void *Libc::Mem_alloc_impl::alloc(size_t size, size_t align_log2)
|
||||
{
|
||||
/* serialize access of heap functions */
|
||||
Lock::Guard lock_guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
/* try allocation at our local allocator */
|
||||
void *out_addr = 0;
|
||||
@ -126,7 +126,7 @@ void *Libc::Mem_alloc_impl::alloc(size_t size, size_t align_log2)
|
||||
void Libc::Mem_alloc_impl::free(void *addr)
|
||||
{
|
||||
/* serialize access of heap functions */
|
||||
Lock::Guard lock_guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
/* forward request to our local allocator */
|
||||
_alloc.free(addr);
|
||||
@ -136,7 +136,7 @@ void Libc::Mem_alloc_impl::free(void *addr)
|
||||
size_t Libc::Mem_alloc_impl::size_at(void const *addr) const
|
||||
{
|
||||
/* serialize access of heap functions */
|
||||
Lock::Guard lock_guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
/* forward request to our local allocator */
|
||||
return _alloc.size_at(addr);
|
||||
|
@ -122,7 +122,7 @@ class Libc::Malloc
|
||||
|
||||
Constructible<Slab_alloc> _slabs[NUM_SLABS]; /* slab allocators */
|
||||
|
||||
Lock _lock;
|
||||
Mutex _mutex;
|
||||
|
||||
unsigned _slab_log2(size_t size) const
|
||||
{
|
||||
@ -155,7 +155,7 @@ class Libc::Malloc
|
||||
|
||||
void * alloc(size_t size)
|
||||
{
|
||||
Lock::Guard lock_guard(_lock);
|
||||
Mutex::Guard guard(_mutex);
|
||||
|
||||
size_t const real_size = size + _room();
|
||||
unsigned const msb = _slab_log2(real_size);
|
||||
@ -206,7 +206,7 @@ class Libc::Malloc
|
||||
|
||||
void free(void *ptr)
|
||||
{
|
||||
Lock::Guard lock_guard(_lock);
|
||||
Mutex::Guard lock_guard(_mutex);
|
||||
|
||||
Metadata *md = (Metadata *)ptr - 1;
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/lock.h>
|
||||
#include <base/mutex.h>
|
||||
#include <libc-plugin/fd_alloc.h>
|
||||
|
||||
/* libc includes */
|
||||
@ -52,7 +52,7 @@ static ssize_t pread_pwrite_impl(Rw_func rw_func, int fd, Buf_type buf, ::size_t
|
||||
if (fdesc == 0)
|
||||
return -1;
|
||||
|
||||
Lock_guard<Lock> rw_lock_guard(fdesc->lock);
|
||||
Mutex::Guard guard(fdesc->mutex);
|
||||
|
||||
::off_t old_offset = lseek(fd, 0, SEEK_CUR);
|
||||
|
||||
|
@ -97,7 +97,7 @@ void Libc::Pthread::join(void **retval)
|
||||
_suspend_ptr->suspend(check);
|
||||
} while (check.retry);
|
||||
|
||||
_join_lock.lock();
|
||||
_join_blockade.block();
|
||||
|
||||
if (retval)
|
||||
*retval = _retval;
|
||||
@ -114,7 +114,7 @@ void Libc::Pthread::cancel()
|
||||
|
||||
_resume_ptr->resume_all();
|
||||
|
||||
_join_lock.unlock();
|
||||
_join_blockade.wakeup();
|
||||
}
|
||||
|
||||
|
||||
@ -125,8 +125,8 @@ void Libc::Pthread::cancel()
|
||||
void Libc::Pthread_registry::insert(Pthread &thread)
|
||||
{
|
||||
/* prevent multiple insertions at the same location */
|
||||
static Lock insert_lock;
|
||||
Lock::Guard insert_lock_guard(insert_lock);
|
||||
static Mutex insert_mutex;
|
||||
Mutex::Guard guard(insert_mutex);
|
||||
|
||||
for (unsigned int i = 0; i < MAX_NUM_PTHREADS; i++) {
|
||||
if (_array[i] == 0) {
|
||||
@ -213,7 +213,7 @@ class pthread_mutex : Genode::Noncopyable
|
||||
protected:
|
||||
|
||||
pthread_t _owner { nullptr };
|
||||
Lock _data_mutex;
|
||||
Mutex _data_mutex;
|
||||
|
||||
/* _data_mutex must be hold when calling the following methods */
|
||||
|
||||
@ -252,11 +252,11 @@ class pthread_mutex : Genode::Noncopyable
|
||||
|
||||
_append_applicant(&applicant);
|
||||
|
||||
_data_mutex.unlock();
|
||||
_data_mutex.release();
|
||||
|
||||
blockade.block();
|
||||
|
||||
_data_mutex.lock();
|
||||
_data_mutex.acquire();
|
||||
|
||||
if (blockade.woken_up()) {
|
||||
return true;
|
||||
@ -326,7 +326,7 @@ struct Libc::Pthread_mutex_normal : pthread_mutex
|
||||
{
|
||||
pthread_t const myself = pthread_self();
|
||||
|
||||
Lock::Guard lock_guard(_data_mutex);
|
||||
Mutex::Guard guard(_data_mutex);
|
||||
|
||||
/* fast path without lock contention */
|
||||
if (_try_lock(myself) == 0)
|
||||
@ -341,7 +341,7 @@ struct Libc::Pthread_mutex_normal : pthread_mutex
|
||||
{
|
||||
pthread_t const myself = pthread_self();
|
||||
|
||||
Lock::Guard lock_guard(_data_mutex);
|
||||
Mutex::Guard guard(_data_mutex);
|
||||
|
||||
/* fast path without lock contention - does not check abstimeout according to spec */
|
||||
if (_try_lock(myself) == 0)
|
||||
@ -364,14 +364,14 @@ struct Libc::Pthread_mutex_normal : pthread_mutex
|
||||
{
|
||||
pthread_t const myself = pthread_self();
|
||||
|
||||
Lock::Guard lock_guard(_data_mutex);
|
||||
Mutex::Guard guard(_data_mutex);
|
||||
|
||||
return _try_lock(myself);
|
||||
}
|
||||
|
||||
int unlock() override final
|
||||
{
|
||||
Lock::Guard lock_guard(_data_mutex);
|
||||
Mutex::Guard guard(_data_mutex);
|
||||
|
||||
if (_owner != pthread_self())
|
||||
return EPERM;
|
||||
@ -400,7 +400,7 @@ struct Libc::Pthread_mutex_errorcheck : pthread_mutex
|
||||
{
|
||||
pthread_t const myself = pthread_self();
|
||||
|
||||
Lock::Guard lock_guard(_data_mutex);
|
||||
Mutex::Guard guard(_data_mutex);
|
||||
|
||||
/* fast path without lock contention (or deadlock) */
|
||||
int const result = _try_lock(myself);
|
||||
@ -422,14 +422,14 @@ struct Libc::Pthread_mutex_errorcheck : pthread_mutex
|
||||
{
|
||||
pthread_t const myself = pthread_self();
|
||||
|
||||
Lock::Guard lock_guard(_data_mutex);
|
||||
Mutex::Guard guard(_data_mutex);
|
||||
|
||||
return _try_lock(myself);
|
||||
}
|
||||
|
||||
int unlock() override final
|
||||
{
|
||||
Lock::Guard lock_guard(_data_mutex);
|
||||
Mutex::Guard guard(_data_mutex);
|
||||
|
||||
if (_owner != pthread_self())
|
||||
return EPERM;
|
||||
@ -463,7 +463,7 @@ struct Libc::Pthread_mutex_recursive : pthread_mutex
|
||||
{
|
||||
pthread_t const myself = pthread_self();
|
||||
|
||||
Lock::Guard lock_guard(_data_mutex);
|
||||
Mutex::Guard guard(_data_mutex);
|
||||
|
||||
/* fast path without lock contention */
|
||||
if (_try_lock(myself) == 0)
|
||||
@ -483,14 +483,14 @@ struct Libc::Pthread_mutex_recursive : pthread_mutex
|
||||
{
|
||||
pthread_t const myself = pthread_self();
|
||||
|
||||
Lock::Guard lock_guard(_data_mutex);
|
||||
Mutex::Guard guard(_data_mutex);
|
||||
|
||||
return _try_lock(myself);
|
||||
}
|
||||
|
||||
int unlock() override final
|
||||
{
|
||||
Lock::Guard lock_guard(_data_mutex);
|
||||
Mutex::Guard guard(_data_mutex);
|
||||
|
||||
if (_owner != pthread_self())
|
||||
return EPERM;
|
||||
@ -880,13 +880,13 @@ extern "C" {
|
||||
static int cond_init(pthread_cond_t *__restrict cond,
|
||||
const pthread_condattr_t *__restrict attr)
|
||||
{
|
||||
static Lock cond_init_lock { };
|
||||
static Mutex cond_init_mutex { };
|
||||
|
||||
if (!cond)
|
||||
return EINVAL;
|
||||
|
||||
try {
|
||||
Lock::Guard g(cond_init_lock);
|
||||
Mutex::Guard guard(cond_init_mutex);
|
||||
Libc::Allocator alloc { };
|
||||
*cond = new (alloc) pthread_cond;
|
||||
return 0;
|
||||
@ -1030,9 +1030,9 @@ extern "C" {
|
||||
};
|
||||
|
||||
|
||||
static Lock &key_list_lock()
|
||||
static Mutex &key_list_mutex()
|
||||
{
|
||||
static Lock inst { };
|
||||
static Mutex inst { };
|
||||
return inst;
|
||||
}
|
||||
|
||||
@ -1055,7 +1055,7 @@ extern "C" {
|
||||
if (!key)
|
||||
return EINVAL;
|
||||
|
||||
Lock_guard<Lock> key_list_lock_guard(key_list_lock());
|
||||
Mutex::Guard guard(key_list_mutex());
|
||||
|
||||
for (int k = 0; k < PTHREAD_KEYS_MAX; k++) {
|
||||
/*
|
||||
@ -1080,7 +1080,7 @@ extern "C" {
|
||||
if (key < 0 || key >= PTHREAD_KEYS_MAX || !keys().key[key].first())
|
||||
return EINVAL;
|
||||
|
||||
Lock_guard<Lock> key_list_lock_guard(key_list_lock());
|
||||
Mutex::Guard guard(key_list_mutex());
|
||||
|
||||
while (Key_element * element = keys().key[key].first()) {
|
||||
keys().key[key].remove(element);
|
||||
@ -1099,7 +1099,7 @@ extern "C" {
|
||||
|
||||
void *myself = Thread::myself();
|
||||
|
||||
Lock_guard<Lock> key_list_lock_guard(key_list_lock());
|
||||
Mutex::Guard guard(key_list_mutex());
|
||||
|
||||
for (Key_element *key_element = keys().key[key].first(); key_element;
|
||||
key_element = key_element->next())
|
||||
@ -1123,7 +1123,7 @@ extern "C" {
|
||||
|
||||
void *myself = Thread::myself();
|
||||
|
||||
Lock_guard<Lock> key_list_lock_guard(key_list_lock());
|
||||
Mutex::Guard guard(key_list_mutex());
|
||||
|
||||
for (Key_element *key_element = keys().key[key].first(); key_element;
|
||||
key_element = key_element->next())
|
||||
@ -1146,8 +1146,8 @@ extern "C" {
|
||||
if (!p) return EINVAL;
|
||||
|
||||
{
|
||||
static Lock lock;
|
||||
Lock::Guard guard(lock);
|
||||
static Mutex mutex;
|
||||
Mutex::Guard guard(mutex);
|
||||
|
||||
if (!once->mutex) {
|
||||
once->mutex = p;
|
||||
|
@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/lock.h>
|
||||
#include <base/mutex.h>
|
||||
#include <util/string.h>
|
||||
|
||||
/* libc includes */
|
||||
@ -74,11 +74,11 @@ void Libc::init_pthread_support(Genode::Cpu_session &cpu_session,
|
||||
|
||||
static unsigned pthread_id()
|
||||
{
|
||||
static Genode::Lock mutex;
|
||||
static Genode::Mutex mutex;
|
||||
|
||||
static unsigned id = 0;
|
||||
|
||||
Genode::Lock::Guard guard(mutex);
|
||||
Genode::Mutex::Guard guard(mutex);
|
||||
|
||||
return id++;
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
*/
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/lock.h>
|
||||
#include <base/mutex.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <sys/uio.h>
|
||||
@ -46,17 +46,13 @@ struct Write
|
||||
};
|
||||
|
||||
|
||||
static Lock &rw_lock()
|
||||
{
|
||||
static Lock rw_lock;
|
||||
return rw_lock;
|
||||
}
|
||||
|
||||
|
||||
template <typename Rw_func>
|
||||
static ssize_t readv_writev_impl(Rw_func rw_func, int fd, const struct iovec *iov, int iovcnt)
|
||||
{
|
||||
Lock_guard<Lock> rw_lock_guard(rw_lock());
|
||||
/* FIXME this should be a pthread_mutex because function uses blocking operations */
|
||||
static Mutex rw_mutex;
|
||||
|
||||
Mutex::Guard guard(rw_mutex);
|
||||
|
||||
char *v;
|
||||
ssize_t bytes_transfered_total = 0;
|
||||
|
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* \brief POSIX readers/writer lock (rwlock) implementation
|
||||
* \author Alexander Senier
|
||||
* \author Christian Helmuth
|
||||
* \date 2018-01-25
|
||||
*/
|
||||
|
||||
@ -13,8 +14,7 @@
|
||||
|
||||
/* Genode includes */
|
||||
#include <base/log.h>
|
||||
#include <base/lock.h>
|
||||
#include <base/lock_guard.h>
|
||||
#include <base/mutex.h>
|
||||
#include <base/thread.h>
|
||||
#include <libc/allocator.h>
|
||||
|
||||
@ -44,26 +44,26 @@ extern "C" {
|
||||
{
|
||||
private:
|
||||
|
||||
Thread *_owner = nullptr;
|
||||
Lock _nbr_mutex {};
|
||||
Lock _global_mutex {};
|
||||
Thread *_owner { nullptr };
|
||||
Mutex _nbr_mutex { };
|
||||
Mutex _global_mutex { };
|
||||
int _nbr = 0;
|
||||
|
||||
public:
|
||||
|
||||
void rdlock()
|
||||
{
|
||||
Lock_guard<Lock> guard(_nbr_mutex);
|
||||
Mutex::Guard guard(_nbr_mutex);
|
||||
++_nbr;
|
||||
if (_nbr == 1) {
|
||||
_global_mutex.lock();
|
||||
_global_mutex.acquire();
|
||||
_owner = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void wrlock()
|
||||
{
|
||||
_global_mutex.lock();
|
||||
_global_mutex.acquire();
|
||||
_owner = Thread::myself();
|
||||
}
|
||||
|
||||
@ -71,11 +71,11 @@ extern "C" {
|
||||
{
|
||||
/* Read lock */
|
||||
if (_owner == nullptr) {
|
||||
Lock_guard<Lock> guard(_nbr_mutex);
|
||||
Mutex::Guard guard(_nbr_mutex);
|
||||
_nbr--;
|
||||
if (_nbr == 0) {
|
||||
_owner = nullptr;
|
||||
_global_mutex.unlock();
|
||||
_global_mutex.release();
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
@ -88,7 +88,7 @@ extern "C" {
|
||||
|
||||
/* Write lock owned by us */
|
||||
_owner = nullptr;
|
||||
_global_mutex.unlock();
|
||||
_global_mutex.release();
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
@ -99,13 +99,13 @@ extern "C" {
|
||||
|
||||
static int rwlock_init(pthread_rwlock_t *rwlock, const pthread_rwlockattr_t *attr)
|
||||
{
|
||||
static Lock rwlock_init_lock { };
|
||||
static Mutex rwlock_init_mutex { };
|
||||
|
||||
if (!rwlock)
|
||||
return EINVAL;
|
||||
|
||||
try {
|
||||
Lock::Guard g(rwlock_init_lock);
|
||||
Mutex::Guard g(rwlock_init_mutex);
|
||||
Libc::Allocator alloc { };
|
||||
*rwlock = new (alloc) struct pthread_rwlock();
|
||||
return 0;
|
||||
|
@ -89,14 +89,14 @@ struct Libc::Select_cb
|
||||
|
||||
struct Libc::Select_cb_list
|
||||
{
|
||||
Lock _mutex;
|
||||
Mutex _mutex;
|
||||
Select_cb *_first = nullptr;
|
||||
|
||||
struct Guard : Lock::Guard
|
||||
struct Guard : Mutex::Guard
|
||||
{
|
||||
Select_cb_list *l;
|
||||
|
||||
Guard(Select_cb_list &list) : Lock::Guard(list._mutex), l(&list) { }
|
||||
Guard(Select_cb_list &list) : Mutex::Guard(list._mutex), l(&list) { }
|
||||
};
|
||||
|
||||
void unsynchronized_insert(Select_cb *scb)
|
||||
|
@ -62,7 +62,7 @@ struct sem : Genode::Noncopyable
|
||||
|
||||
Applicant *_applicants { nullptr };
|
||||
int _count;
|
||||
Lock _data_mutex;
|
||||
Mutex _data_mutex;
|
||||
|
||||
/* _data_mutex must be hold when calling the following methods */
|
||||
|
||||
@ -100,11 +100,11 @@ struct sem : Genode::Noncopyable
|
||||
|
||||
_append_applicant(&applicant);
|
||||
|
||||
_data_mutex.unlock();
|
||||
_data_mutex.release();
|
||||
|
||||
blockade.block();
|
||||
|
||||
_data_mutex.lock();
|
||||
_data_mutex.acquire();
|
||||
|
||||
if (blockade.woken_up()) {
|
||||
return true;
|
||||
@ -158,14 +158,14 @@ struct sem : Genode::Noncopyable
|
||||
|
||||
int trydown()
|
||||
{
|
||||
Lock::Guard lock_guard(_data_mutex);
|
||||
Mutex::Guard guard(_data_mutex);
|
||||
|
||||
return _try_down();
|
||||
}
|
||||
|
||||
int down()
|
||||
{
|
||||
Lock::Guard lock_guard(_data_mutex);
|
||||
Mutex::Guard guard(_data_mutex);
|
||||
|
||||
/* fast path */
|
||||
if (_try_down() == 0)
|
||||
@ -178,7 +178,7 @@ struct sem : Genode::Noncopyable
|
||||
|
||||
int down_timed(timespec const &abs_timeout)
|
||||
{
|
||||
Lock::Guard lock_guard(_data_mutex);
|
||||
Mutex::Guard guard(_data_mutex);
|
||||
|
||||
/* fast path */
|
||||
if (_try_down() == 0)
|
||||
@ -200,7 +200,7 @@ struct sem : Genode::Noncopyable
|
||||
|
||||
int up()
|
||||
{
|
||||
Lock::Guard lock_guard(_data_mutex);
|
||||
Mutex::Guard guard(_data_mutex);
|
||||
|
||||
_count_up();
|
||||
|
||||
|
@ -1048,8 +1048,10 @@ static int read_ifaddr_file(sockaddr_in &sockaddr, Socket_fs::Absolute_path cons
|
||||
|
||||
extern "C" int getifaddrs(struct ifaddrs **ifap)
|
||||
{
|
||||
static Lock lock;
|
||||
Lock::Guard guard(lock);
|
||||
/* FIXME this should be a pthread_mutex because function uses blocking operations */
|
||||
static Mutex mutex;
|
||||
|
||||
Mutex::Guard guard(mutex);
|
||||
|
||||
static sockaddr_in address;
|
||||
static sockaddr_in netmask { 0 };
|
||||
|
@ -63,15 +63,15 @@ static void suspend(Libc::Suspend_functor &check)
|
||||
};
|
||||
|
||||
|
||||
static Genode::Lock &vfs_lock()
|
||||
static Genode::Mutex &vfs_mutex()
|
||||
{
|
||||
static Genode::Lock _vfs_lock;
|
||||
return _vfs_lock;
|
||||
static Genode::Mutex mutex;
|
||||
return mutex;
|
||||
}
|
||||
|
||||
|
||||
#define VFS_THREAD_SAFE(code) ({ \
|
||||
Genode::Lock::Guard g(vfs_lock()); \
|
||||
Genode::Mutex::Guard g(vfs_mutex()); \
|
||||
code; \
|
||||
})
|
||||
|
||||
@ -237,7 +237,7 @@ void Libc::Vfs_plugin::_with_info(File_descriptor &fd, FN const &fn)
|
||||
path.append_element("info");
|
||||
|
||||
try {
|
||||
Lock::Guard g(vfs_lock());
|
||||
Mutex::Guard g(vfs_mutex());
|
||||
|
||||
File_content const content(_alloc, *_root_dir, path.string(),
|
||||
File_content::Limit{4096U});
|
||||
|
Loading…
Reference in New Issue
Block a user