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

@@ -21,7 +21,7 @@
/* Genode includes */
#include <base/stdint.h>
#include <base/lock.h>
#include <base/mutex.h>
#include <util/avl_tree.h>
#include <util/noncopyable.h>
@@ -32,12 +32,12 @@ namespace Genode {
private:
Lock _lock { };
Mutex _mutex { };
addr_t _base = 0;
addr_t _last = 0;
enum {
HEADER = sizeof(_base) + sizeof(_lock) + sizeof(_last),
HEADER = sizeof(_base) + sizeof(_mutex) + sizeof(_last),
CAP_RANGE_SIZE = 4096,
WORDS = (CAP_RANGE_SIZE - HEADER - sizeof(Avl_node<Cap_range>)) / sizeof(addr_t),
};

View File

@@ -78,7 +78,7 @@ namespace Genode {
addr_t _initial_eip = 0;
addr_t _client_exc_pt_sel;
Lock _state_lock { };
Mutex _state_lock { };
struct
{
@@ -230,7 +230,7 @@ namespace Genode {
*/
bool copy_thread_state(Thread_state * state_dst)
{
Lock::Guard _state_lock_guard(_state_lock);
Mutex::Guard _state_lock_guard(_state_lock);
if (!state_dst || !_state.blocked())
return false;
@@ -245,7 +245,7 @@ namespace Genode {
*/
bool copy_thread_state(Thread_state state_src)
{
Lock::Guard _state_lock_guard(_state_lock);
Mutex::Guard _state_lock_guard(_state_lock);
if (!_state.blocked())
return false;
@@ -267,12 +267,12 @@ namespace Genode {
inline void single_step(bool on)
{
_state_lock.lock();
_state_lock.acquire();
if (_state.is_dead() || !_state.blocked() ||
(on && (_state._status & _state.SINGLESTEP)) ||
(!on && !(_state._status & _state.SINGLESTEP))) {
_state_lock.unlock();
_state_lock.release();
return;
}
@@ -281,7 +281,7 @@ namespace Genode {
else
_state._status &= ~_state.SINGLESTEP;
_state_lock.unlock();
_state_lock.release();
/* force client in exit and thereby apply single_step change */
client_recall(false);

View File

@@ -16,7 +16,7 @@
/* Genode includes */
#include <util/list.h>
#include <base/lock.h>
#include <base/mutex.h>
#include <base/capability.h>
#include <base/tslab.h>
#include <base/log.h>
@@ -40,7 +40,7 @@ class Genode::Rpc_cap_factory
Tslab<Cap_object, SBS> _slab;
List<Cap_object> _list { };
Lock _lock { };
Mutex _mutex { };
public:

View File

@@ -138,7 +138,7 @@ void Pager_object::_page_fault_handler(Pager_object &obj)
* handler thread which may respond via wake_up() (ep thread) before
* we are done here - we have to lock the whole page lookup procedure
*/
obj._state_lock.lock();
obj._state_lock.acquire();
obj._state.thread.ip = ipc_pager.fault_ip();
obj._state.thread.sp = 0;
@@ -164,7 +164,7 @@ void Pager_object::_page_fault_handler(Pager_object &obj)
if (res == Nova::NOVA_PD_OOM) {
obj._state.unblock_pause_sm();
obj._state.unblock();
obj._state_lock.unlock();
obj._state_lock.release();
/* block until revoke is due */
ipc_pager.reply_and_wait_for_fault(obj.sel_sm_block_oom());
@@ -178,7 +178,7 @@ void Pager_object::_page_fault_handler(Pager_object &obj)
if (!error) {
obj._state.unblock_pause_sm();
obj._state.unblock();
obj._state_lock.unlock();
obj._state_lock.release();
ipc_pager.reply_and_wait_for_fault();
}
@@ -196,7 +196,7 @@ void Pager_object::_page_fault_handler(Pager_object &obj)
/* region manager fault - to be handled */
log("page fault, ", fault_info, " reason=", error);
obj._state_lock.unlock();
obj._state_lock.release();
/* block the faulting thread until region manager is done */
ipc_pager.reply_and_wait_for_fault(obj.sel_sm_block_pause());
@@ -218,7 +218,7 @@ void Pager_object::exception(uint8_t exit_id)
uint8_t res = 0xFF;
addr_t mtd = 0;
_state_lock.lock();
_state_lock.acquire();
/* remember exception type for Cpu_session::state() calls */
_state.thread.trapno = exit_id;
@@ -254,7 +254,7 @@ void Pager_object::exception(uint8_t exit_id)
}
}
_state_lock.unlock();
_state_lock.release();
utcb.set_msg_word(0);
utcb.mtd = mtd;
@@ -268,7 +268,7 @@ void Pager_object::_recall_handler(Pager_object &obj)
Thread &myself = *Thread::myself();
Utcb &utcb = *reinterpret_cast<Utcb *>(myself.utcb());
obj._state_lock.lock();
obj._state_lock.acquire();
if (obj._state.modified) {
obj._copy_state_to_utcb(utcb);
@@ -299,7 +299,7 @@ void Pager_object::_recall_handler(Pager_object &obj)
obj._state.block_pause_sm();
}
obj._state_lock.unlock();
obj._state_lock.release();
utcb.set_msg_word(0);
reply(myself.stack_top(), sm);
@@ -429,7 +429,7 @@ void Pager_object::_invoke_handler(Pager_object &obj)
void Pager_object::wake_up()
{
Lock::Guard _state_lock_guard(_state_lock);
Mutex::Guard _state_lock_guard(_state_lock);
if (!_state.blocked())
return;
@@ -467,7 +467,7 @@ void Pager_object::client_cancel_blocking()
uint8_t Pager_object::client_recall(bool get_state_and_block)
{
Lock::Guard _state_lock_guard(_state_lock);
Mutex::Guard _state_lock_guard(_state_lock);
return _unsynchronized_client_recall(get_state_and_block);
}

View File

@@ -29,7 +29,7 @@ Native_capability Rpc_cap_factory::alloc(Native_capability ep, addr_t entry, add
using namespace Nova;
Lock::Guard guard(_lock);
Mutex::Guard guard(_mutex);
/* create cap object */
Cap_object * pt_cap = new (&_slab) Cap_object(pt_sel);
@@ -64,7 +64,7 @@ void Rpc_cap_factory::free(Native_capability cap)
{
if (!cap.valid()) return;
Lock::Guard guard(_lock);
Mutex::Guard guard(_mutex);
for (Cap_object *obj = _list.first(); obj ; obj = obj->next()) {
if (cap.local_name() == (long)obj->_cap_sel) {
@@ -86,7 +86,7 @@ Rpc_cap_factory::Rpc_cap_factory(Allocator &md_alloc)
Rpc_cap_factory::~Rpc_cap_factory()
{
Lock::Guard guard(_lock);
Mutex::Guard guard(_mutex);
for (Cap_object *obj; (obj = _list.first()); ) {
Nova::revoke(Nova::Obj_crd(obj->_cap_sel, 0));

View File

@@ -46,7 +46,7 @@ void Cap_range::inc(unsigned id)
{
bool failure = false;
{
Lock::Guard guard(_lock);
Mutex::Guard guard(_mutex);
if (_cap_array[id] + 1 == 0)
failure = true;
@@ -65,7 +65,7 @@ void Cap_range::dec(unsigned const id_start, bool revoke, unsigned num_log_2)
{
unsigned const end = min(id_start + (1U << num_log_2), elements());
Lock::Guard guard(_lock);
Mutex::Guard guard(_mutex);
for (unsigned id = id_start; id < end; id++) {
if (_cap_array[id] == 0) {
@@ -92,7 +92,7 @@ addr_t Cap_range::alloc(size_t const num_log2)
addr_t const step = 1UL << num_log2;
{
Lock::Guard guard(_lock);
Mutex::Guard guard(_mutex);
unsigned max = elements();
addr_t last = _last;