Commit a002d5af by Christian Kern

Replace mtapi spinlock usage with embb spinlocks

parent 1c8c0ec5
......@@ -29,6 +29,7 @@
#include <embb_mtapi_alloc.h>
#include <embb_mtapi_log.h>
#include <embb_mtapi_id_pool_t.h>
#include <embb/base/c/mutex.h>
void embb_mtapi_id_pool_initialize(
embb_mtapi_id_pool_t * that,
......@@ -45,7 +46,7 @@ void embb_mtapi_id_pool_initialize(
that->ids_available = capacity;
that->put_id_position = 0;
that->get_id_position = 1;
embb_mtapi_spinlock_initialize(&that->lock);
embb_spin_init(&that->lock);
}
void embb_mtapi_id_pool_finalize(embb_mtapi_id_pool_t * that) {
......@@ -55,7 +56,7 @@ void embb_mtapi_id_pool_finalize(embb_mtapi_id_pool_t * that) {
that->put_id_position = 0;
embb_mtapi_alloc_deallocate(that->id_buffer);
that->id_buffer = NULL;
embb_mtapi_spinlock_finalize(&that->lock);
embb_spin_destroy(&that->lock);
}
mtapi_uint_t embb_mtapi_id_pool_allocate(embb_mtapi_id_pool_t * that) {
......@@ -63,7 +64,7 @@ mtapi_uint_t embb_mtapi_id_pool_allocate(embb_mtapi_id_pool_t * that) {
assert(MTAPI_NULL != that);
if (embb_mtapi_spinlock_acquire(&that->lock)) {
if (embb_spin_lock(&that->lock) == EMBB_SUCCESS) {
if (0 < that->ids_available) {
/* take away one id */
that->ids_available--;
......@@ -81,7 +82,7 @@ mtapi_uint_t embb_mtapi_id_pool_allocate(embb_mtapi_id_pool_t * that) {
/* make id entry invalid just in case */
that->id_buffer[id_position] = EMBB_MTAPI_IDPOOL_INVALID_ID;
}
embb_mtapi_spinlock_release(&that->lock);
embb_spin_unlock(&that->lock);
}
return id;
......@@ -92,7 +93,7 @@ void embb_mtapi_id_pool_deallocate(
mtapi_uint_t id) {
assert(MTAPI_NULL != that);
if (embb_mtapi_spinlock_acquire(&that->lock)) {
if (embb_spin_lock(&that->lock) == EMBB_SUCCESS) {
if (that->capacity > that->ids_available) {
/* acquire position to put id to */
mtapi_uint_t id_position = that->put_id_position;
......@@ -107,7 +108,7 @@ void embb_mtapi_id_pool_deallocate(
/* make it available */
that->ids_available++;
}
embb_mtapi_spinlock_release(&that->lock);
embb_spin_unlock(&that->lock);
} else {
embb_mtapi_log_error(
"could not acquire lock in embb_mtapi_IdPool_deallocate\n");
......
......@@ -29,8 +29,7 @@
#include <embb/mtapi/c/mtapi.h>
#include <embb/base/c/atomic.h>
#include <embb_mtapi_spinlock_t.h>
#include <embb/base/c/mutex.h>
#ifdef __cplusplus
extern "C" {
......@@ -51,7 +50,7 @@ struct embb_mtapi_id_pool_struct {
mtapi_uint_t ids_available;
mtapi_uint_t get_id_position;
mtapi_uint_t put_id_position;
embb_mtapi_spinlock_t lock;
embb_spinlock_t lock;
};
/**
......
......@@ -41,7 +41,6 @@
static embb_mtapi_node_t* embb_mtapi_node_instance = NULL;
extern embb_atomic_int embb_mtapi_spinlock_spins;
/* ---- CLASS MEMBERS ------------------------------------------------------ */
......@@ -87,8 +86,6 @@ void mtapi_initialize(
/* out of memory! */
local_status = MTAPI_ERR_UNKNOWN;
} else {
embb_atomic_store_int(&embb_mtapi_spinlock_spins, 0);
node = embb_mtapi_node_instance;
node->domain_id = domain_id;
......@@ -184,9 +181,6 @@ void mtapi_finalize(MTAPI_OUT mtapi_status_t* status) {
embb_mtapi_alloc_deallocate(node);
embb_mtapi_node_instance = MTAPI_NULL;
embb_mtapi_log_info("mtapi spinlock spun %d times.\n",
embb_atomic_load_int(&embb_mtapi_spinlock_spins));
local_status = MTAPI_SUCCESS;
} else {
local_status = MTAPI_ERR_NODE_NOTINIT;
......
......@@ -31,7 +31,7 @@
#include <embb/base/c/atomic.h>
#include <embb_mtapi_pool_template.h>
#include <embb_mtapi_spinlock_t.h>
#include <embb/base/c/mutex.h>
#ifdef __cplusplus
extern "C" {
......
......@@ -46,7 +46,7 @@ void embb_mtapi_task_queue_initialize(embb_mtapi_task_queue_t* that) {
that->get_task_position = 0;
that->put_task_position = 0;
mtapi_queueattr_init(&that->attributes, MTAPI_NULL);
embb_mtapi_spinlock_initialize(&that->lock);
embb_spin_init(&that->lock);
}
void embb_mtapi_task_queue_initialize_with_capacity(
......@@ -61,7 +61,7 @@ void embb_mtapi_task_queue_initialize_with_capacity(
that->put_task_position = 0;
mtapi_queueattr_init(&that->attributes, MTAPI_NULL);
that->attributes.limit = capacity;
embb_mtapi_spinlock_initialize(&that->lock);
embb_spin_init(&that->lock);
}
void embb_mtapi_task_queue_finalize(embb_mtapi_task_queue_t* that) {
......@@ -70,7 +70,7 @@ void embb_mtapi_task_queue_finalize(embb_mtapi_task_queue_t* that) {
embb_mtapi_task_queue_initialize(that);
embb_mtapi_spinlock_finalize(&that->lock);
embb_spin_destroy(&that->lock);
}
embb_mtapi_task_t * embb_mtapi_task_queue_pop(embb_mtapi_task_queue_t* that) {
......@@ -78,7 +78,7 @@ embb_mtapi_task_t * embb_mtapi_task_queue_pop(embb_mtapi_task_queue_t* that) {
assert(MTAPI_NULL != that);
if (embb_mtapi_spinlock_acquire_with_spincount(&that->lock, 128)) {
if (embb_spin_try_lock(&that->lock, 128) == EMBB_SUCCESS) {
if (0 < that->tasks_available) {
/* take away one task */
that->tasks_available--;
......@@ -96,7 +96,7 @@ embb_mtapi_task_t * embb_mtapi_task_queue_pop(embb_mtapi_task_queue_t* that) {
/* make task entry invalid just in case */
that->task_buffer[task_position] = MTAPI_NULL;
}
embb_mtapi_spinlock_release(&that->lock);
embb_spin_unlock(&that->lock);
}
return task;
......@@ -109,7 +109,7 @@ mtapi_boolean_t embb_mtapi_task_queue_push(
assert(MTAPI_NULL != that);
if (embb_mtapi_spinlock_acquire(&that->lock)) {
if (embb_spin_lock(&that->lock) == EMBB_SUCCESS) {
if (that->attributes.limit > that->tasks_available) {
/* acquire position to put task into */
mtapi_uint_t task_position = that->put_task_position;
......@@ -126,7 +126,7 @@ mtapi_boolean_t embb_mtapi_task_queue_push(
result = MTAPI_TRUE;
}
embb_mtapi_spinlock_release(&that->lock);
embb_spin_unlock(&that->lock);
}
return result;
......@@ -143,7 +143,7 @@ mtapi_boolean_t embb_mtapi_task_queue_process(
assert(MTAPI_NULL != that);
assert(MTAPI_NULL != process);
if (embb_mtapi_spinlock_acquire(&that->lock)) {
if (embb_spin_lock(&that->lock) == EMBB_SUCCESS) {
idx = that->get_task_position;
for (ii = 0; ii < that->tasks_available; ii++) {
result = process(that->task_buffer[ii], user_data);
......@@ -152,7 +152,7 @@ mtapi_boolean_t embb_mtapi_task_queue_process(
}
idx = (idx + 1) % that->attributes.limit;
}
embb_mtapi_spinlock_release(&that->lock);
embb_spin_unlock(&that->lock);
}
return result;
......
......@@ -30,7 +30,7 @@
#include <embb/mtapi/c/mtapi.h>
#include <embb/base/c/atomic.h>
#include <embb_mtapi_spinlock_t.h>
#include <embb/base/c/mutex.h>
#include <embb_mtapi_task_visitor_function_t.h>
#ifdef __cplusplus
......@@ -57,7 +57,7 @@ struct embb_mtapi_task_queue_struct {
mtapi_uint_t get_task_position;
mtapi_uint_t put_task_position;
mtapi_queue_attributes_t attributes;
embb_mtapi_spinlock_t lock;
embb_spinlock_t lock;
};
#include <embb_mtapi_task_queue_t_fwd.h>
......
......@@ -85,14 +85,14 @@ void embb_mtapi_task_initialize(embb_mtapi_task_t* that) {
that->queue.id = EMBB_MTAPI_IDPOOL_INVALID_ID;
that->error_code = MTAPI_SUCCESS;
embb_atomic_store_unsigned_int(&that->current_instance, 0);
embb_mtapi_spinlock_initialize(&that->state_lock);
embb_spin_init(&that->state_lock);
}
void embb_mtapi_task_finalize(embb_mtapi_task_t* that) {
assert(MTAPI_NULL != that);
embb_mtapi_task_initialize(that);
embb_mtapi_spinlock_finalize(&that->state_lock);
embb_spin_destroy(&that->state_lock);
}
mtapi_boolean_t embb_mtapi_task_execute(
......@@ -158,10 +158,10 @@ void embb_mtapi_task_set_state(
mtapi_task_state_t state) {
assert(MTAPI_NULL != that);
embb_mtapi_spinlock_acquire(&that->state_lock);
embb_spin_lock(&that->state_lock);
that->state = state;
embb_atomic_memory_barrier();
embb_mtapi_spinlock_release(&that->state_lock);
embb_spin_unlock(&that->state_lock);
}
static mtapi_task_hndl_t embb_mtapi_task_start(
......
......@@ -31,7 +31,7 @@
#include <embb/base/c/atomic.h>
#include <embb_mtapi_pool_template.h>
#include <embb_mtapi_spinlock_t.h>
#include <embb/base/c/mutex.h>
#ifdef __cplusplus
extern "C" {
......@@ -65,7 +65,7 @@ struct embb_mtapi_task_struct {
mtapi_queue_hndl_t queue;
mtapi_action_hndl_t action;
embb_mtapi_spinlock_t state_lock;
embb_spinlock_t state_lock;
volatile mtapi_task_state_t state;
embb_atomic_unsigned_int current_instance;
embb_atomic_unsigned_int instances_todo;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment