Fiasco.OC: make capability ref-counter thread-safe
Introduce process global spin-lock for Cap_index's reference-counter to avoid non-atomic increment/decrement of the counter. Here, we don't use a static Spinlock object, because it's constructor wouldn't be initialized before used for the first time.
This commit is contained in:
parent
94e14ec20b
commit
54e08cfed5
|
@ -64,8 +64,8 @@ namespace Genode
|
||||||
bool used() const { return _id != UNUSED; }
|
bool used() const { return _id != UNUSED; }
|
||||||
uint16_t id() const { return _id; }
|
uint16_t id() const { return _id; }
|
||||||
void id(uint16_t id) { _id = id; }
|
void id(uint16_t id) { _id = id; }
|
||||||
uint8_t inc() { return ++_ref_cnt; }
|
uint8_t inc();
|
||||||
uint8_t dec() { return --_ref_cnt; }
|
uint8_t dec();
|
||||||
addr_t kcap();
|
addr_t kcap();
|
||||||
|
|
||||||
void* operator new (size_t size, Cap_index* idx) { return idx; }
|
void* operator new (size_t size, Cap_index* idx) { return idx; }
|
||||||
|
|
|
@ -18,6 +18,9 @@
|
||||||
|
|
||||||
#include <util/assert.h>
|
#include <util/assert.h>
|
||||||
|
|
||||||
|
/* Lock implementation local include */
|
||||||
|
#include <spin_lock.h>
|
||||||
|
|
||||||
namespace Fiasco {
|
namespace Fiasco {
|
||||||
#include <l4/sys/consts.h>
|
#include <l4/sys/consts.h>
|
||||||
#include <l4/sys/task.h>
|
#include <l4/sys/task.h>
|
||||||
|
@ -28,6 +31,9 @@ namespace Fiasco {
|
||||||
** Cap_index class **
|
** Cap_index class **
|
||||||
***********************/
|
***********************/
|
||||||
|
|
||||||
|
static volatile int _cap_index_spinlock = SPINLOCK_UNLOCKED;
|
||||||
|
|
||||||
|
|
||||||
bool Genode::Cap_index::higher(Genode::Cap_index *n) { return n->_id > _id; }
|
bool Genode::Cap_index::higher(Genode::Cap_index *n) { return n->_id > _id; }
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +52,24 @@ Genode::addr_t Genode::Cap_index::kcap() {
|
||||||
return cap_idx_alloc()->idx_to_kcap(this); }
|
return cap_idx_alloc()->idx_to_kcap(this); }
|
||||||
|
|
||||||
|
|
||||||
|
Genode::uint8_t Genode::Cap_index::inc()
|
||||||
|
{
|
||||||
|
spinlock_lock(&_cap_index_spinlock);
|
||||||
|
Genode::uint8_t ret = ++_ref_cnt;
|
||||||
|
spinlock_unlock(&_cap_index_spinlock);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Genode::uint8_t Genode::Cap_index::dec()
|
||||||
|
{
|
||||||
|
spinlock_lock(&_cap_index_spinlock);
|
||||||
|
Genode::uint8_t ret = --_ref_cnt;
|
||||||
|
spinlock_unlock(&_cap_index_spinlock);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************************
|
/****************************
|
||||||
** Capability_map class **
|
** Capability_map class **
|
||||||
****************************/
|
****************************/
|
||||||
|
|
Loading…
Reference in New Issue