Commit f58e653a by Marcus Winter

base_c: atomic initialization check in debug mode, atomic initialization with value

parent 61caf1ab
...@@ -320,8 +320,6 @@ void embb_mutex_destroy( ...@@ -320,8 +320,6 @@ void embb_mutex_destroy(
#define EMBB_ATOMIC_MUTEX_LOCK(mutex) embb_mutex_lock(&(mutex)) #define EMBB_ATOMIC_MUTEX_LOCK(mutex) embb_mutex_lock(&(mutex))
#define EMBB_ATOMIC_MUTEX_UNLOCK(mutex) embb_mutex_unlock(&(mutex)) #define EMBB_ATOMIC_MUTEX_UNLOCK(mutex) embb_mutex_unlock(&(mutex))
#define EMBB_ATOMIC_MUTEX_DESTROY(mutex) embb_mutex_destroy(&(mutex)) #define EMBB_ATOMIC_MUTEX_DESTROY(mutex) embb_mutex_destroy(&(mutex))
#define EMBB_ATOMIC_INIT_CHECK(variable) assert(variable->marker == 0x12345678)
#define EMBB_ATOMIC_INIT_MARKER(variable) variable->marker = 0x12345678
#else #else
...@@ -329,6 +327,16 @@ void embb_mutex_destroy( ...@@ -329,6 +327,16 @@ void embb_mutex_destroy(
#define EMBB_ATOMIC_MUTEX_LOCK(...) #define EMBB_ATOMIC_MUTEX_LOCK(...)
#define EMBB_ATOMIC_MUTEX_UNLOCK(...) #define EMBB_ATOMIC_MUTEX_UNLOCK(...)
#define EMBB_ATOMIC_MUTEX_DESTROY(...) #define EMBB_ATOMIC_MUTEX_DESTROY(...)
#endif
#ifdef EMBB_DEBUG
#define EMBB_ATOMIC_INIT_CHECK(variable) assert(variable->marker == 0x12345678)
#define EMBB_ATOMIC_INIT_MARKER(variable) variable->marker = 0x12345678
#else
#define EMBB_ATOMIC_INIT_CHECK(variable) (void)(variable) #define EMBB_ATOMIC_INIT_CHECK(variable) (void)(variable)
#define EMBB_ATOMIC_INIT_MARKER(variable) (void)(variable) #define EMBB_ATOMIC_INIT_MARKER(variable) (void)(variable)
......
...@@ -35,6 +35,8 @@ ...@@ -35,6 +35,8 @@
#include <intrin.h> #include <intrin.h>
#endif #endif
#ifdef EMBB_DEBUG
#ifdef EMBB_THREADING_ANALYSIS_MODE #ifdef EMBB_THREADING_ANALYSIS_MODE
#define EMBB_ATOMIC_INTERNAL_DEFINE_VARIABLE( \ #define EMBB_ATOMIC_INTERNAL_DEFINE_VARIABLE( \
...@@ -55,10 +57,38 @@ ...@@ -55,10 +57,38 @@
typedef struct \ typedef struct \
{ \ { \
volatile EMBB_ATOMIC_PARAMETER_TYPE_NATIVE internal_variable; \ volatile EMBB_ATOMIC_PARAMETER_TYPE_NATIVE internal_variable; \
uint32_t marker; \
} EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX); } EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX);
#endif #endif
#else
#ifdef EMBB_THREADING_ANALYSIS_MODE
#define EMBB_ATOMIC_INTERNAL_DEFINE_VARIABLE( \
EMBB_ATOMIC_PARAMETER_TYPE_NATIVE, \
EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX) \
typedef struct \
{ \
volatile EMBB_ATOMIC_PARAMETER_TYPE_NATIVE internal_variable; \
embb_mutex_t internal_mutex; \
} EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX);
#else
#define EMBB_ATOMIC_INTERNAL_DEFINE_VARIABLE( \
EMBB_ATOMIC_PARAMETER_TYPE_NATIVE, \
EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX) \
typedef struct \
{ \
volatile EMBB_ATOMIC_PARAMETER_TYPE_NATIVE internal_variable; \
} EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX);
#endif
#endif
EMBB_ATOMIC_INTERNAL_DEFINE_VARIABLE(char, char) EMBB_ATOMIC_INTERNAL_DEFINE_VARIABLE(char, char)
EMBB_ATOMIC_INTERNAL_DEFINE_VARIABLE(short, short) EMBB_ATOMIC_INTERNAL_DEFINE_VARIABLE(short, short)
EMBB_ATOMIC_INTERNAL_DEFINE_VARIABLE(unsigned short, unsigned_short) EMBB_ATOMIC_INTERNAL_DEFINE_VARIABLE(unsigned short, unsigned_short)
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <embb/base/c/internal/atomic/atomic_sizes.h> #include <embb/base/c/internal/atomic/atomic_sizes.h>
#include <embb/base/c/internal/macro_helper.h> #include <embb/base/c/internal/macro_helper.h>
#include <embb/base/c/internal/atomic/atomic_variables.h> #include <embb/base/c/internal/atomic/atomic_variables.h>
#include <embb/base/c/internal/atomic/store.h>
#include <string.h> #include <string.h>
/* /*
...@@ -41,9 +42,11 @@ ...@@ -41,9 +42,11 @@
*/ */
#define EMBB_ATOMIC_INTERNAL_DEFINE_INIT_METHOD(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) \ #define EMBB_ATOMIC_INTERNAL_DEFINE_INIT_METHOD(EMBB_ATOMIC_PARAMETER_TYPE_NATIVE, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX, EMBB_ATOMIC_PARAMETER_TYPE_SIZE) \
EMBB_PLATFORM_INLINE void EMBB_CAT2(embb_atomic_init_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(\ EMBB_PLATFORM_INLINE void EMBB_CAT2(embb_atomic_init_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(\
EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)* variable) { \ EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)* variable, \
EMBB_ATOMIC_PARAMETER_TYPE_NATIVE value) { \
EMBB_ATOMIC_MUTEX_INIT(variable->internal_mutex); \ EMBB_ATOMIC_MUTEX_INIT(variable->internal_mutex); \
EMBB_ATOMIC_INIT_MARKER(variable); \ EMBB_ATOMIC_INIT_MARKER(variable); \
EMBB_CAT2(embb_atomic_store_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(variable, value); \
} }
#undef EMBB_ATOMIC_METHOD_TO_GENERATE #undef EMBB_ATOMIC_METHOD_TO_GENERATE
......
...@@ -33,8 +33,7 @@ int embb_counter_init(embb_counter_t* counter) { ...@@ -33,8 +33,7 @@ int embb_counter_init(embb_counter_t* counter) {
if (counter == NULL) { if (counter == NULL) {
return EMBB_ERROR; return EMBB_ERROR;
} }
embb_atomic_init_unsigned_int(&(counter->value)); embb_atomic_init_unsigned_int(&(counter->value), 0);
embb_atomic_store_unsigned_int(&(counter->value), 0);
return EMBB_SUCCESS; return EMBB_SUCCESS;
} }
......
...@@ -147,10 +147,7 @@ int embb_spin_init(embb_spinlock_t* spinlock) { ...@@ -147,10 +147,7 @@ int embb_spin_init(embb_spinlock_t* spinlock) {
if (NULL == spinlock) { if (NULL == spinlock) {
return EMBB_ERROR; return EMBB_ERROR;
} }
// For now, store the initial value. In the future will use atomic init embb_atomic_init_int(&spinlock->atomic_spin_variable_, 0);
// function (as soon as available).
embb_atomic_init_int(&spinlock->atomic_spin_variable_);
embb_atomic_store_int(&spinlock->atomic_spin_variable_, 0);
return EMBB_SUCCESS; return EMBB_SUCCESS;
} }
......
...@@ -40,8 +40,7 @@ embb_atomic_int flag; ...@@ -40,8 +40,7 @@ embb_atomic_int flag;
ThreadIndexTest::ThreadIndexTest() ThreadIndexTest::ThreadIndexTest()
: number_threads_(partest::TestSuite::GetDefaultNumThreads()) { : number_threads_(partest::TestSuite::GetDefaultNumThreads()) {
embb_atomic_init_int(&flag); embb_atomic_init_int(&flag, 1);
embb_atomic_store_int(&flag, 1);
CreateUnit("Test 0 indices").Add(&ThreadIndexTest::Test0, this); CreateUnit("Test 0 indices").Add(&ThreadIndexTest::Test0, this);
CreateUnit("Test 1 index").Add(&ThreadIndexTest::Test1, this); CreateUnit("Test 1 index").Add(&ThreadIndexTest::Test1, this);
......
...@@ -62,8 +62,7 @@ mtapi_action_hndl_t mtapi_ext_plugin_action_create( ...@@ -62,8 +62,7 @@ mtapi_action_hndl_t mtapi_ext_plugin_action_create(
new_action->node_local_data_size = node_local_data_size; new_action->node_local_data_size = node_local_data_size;
new_action->enabled = MTAPI_TRUE; new_action->enabled = MTAPI_TRUE;
new_action->is_plugin_action = MTAPI_TRUE; new_action->is_plugin_action = MTAPI_TRUE;
embb_atomic_init_int(&new_action->num_tasks); embb_atomic_init_int(&new_action->num_tasks, 0);
embb_atomic_store_int(&new_action->num_tasks, 0);
new_action->plugin_task_start_function = task_start_function; new_action->plugin_task_start_function = task_start_function;
new_action->plugin_task_cancel_function = task_cancel_function; new_action->plugin_task_cancel_function = task_cancel_function;
......
...@@ -59,8 +59,7 @@ void embb_mtapi_action_initialize(embb_mtapi_action_t* that) { ...@@ -59,8 +59,7 @@ void embb_mtapi_action_initialize(embb_mtapi_action_t* that) {
that->node_local_data = NULL; that->node_local_data = NULL;
that->node_local_data_size = 0; that->node_local_data_size = 0;
that->plugin_data = MTAPI_NULL; that->plugin_data = MTAPI_NULL;
embb_atomic_init_int(&that->num_tasks); embb_atomic_init_int(&that->num_tasks, 0);
embb_atomic_store_int(&that->num_tasks, 0);
} }
void embb_mtapi_action_finalize(embb_mtapi_action_t* that) { void embb_mtapi_action_finalize(embb_mtapi_action_t* that) {
...@@ -153,8 +152,7 @@ mtapi_action_hndl_t mtapi_action_create( ...@@ -153,8 +152,7 @@ mtapi_action_hndl_t mtapi_action_create(
new_action->node_local_data_size = node_local_data_size; new_action->node_local_data_size = node_local_data_size;
new_action->enabled = MTAPI_TRUE; new_action->enabled = MTAPI_TRUE;
new_action->is_plugin_action = MTAPI_FALSE; new_action->is_plugin_action = MTAPI_FALSE;
embb_atomic_init_int(&new_action->num_tasks); embb_atomic_init_int(&new_action->num_tasks, 0);
embb_atomic_store_int(&new_action->num_tasks, 0);
new_action->action_function = action_function; new_action->action_function = action_function;
......
...@@ -55,10 +55,8 @@ void embb_mtapi_group_initialize(embb_mtapi_group_t * that) { ...@@ -55,10 +55,8 @@ void embb_mtapi_group_initialize(embb_mtapi_group_t * that) {
assert(MTAPI_NULL != that); assert(MTAPI_NULL != that);
that->group_id = MTAPI_GROUP_ID_NONE; that->group_id = MTAPI_GROUP_ID_NONE;
embb_atomic_init_int(&that->deleted); embb_atomic_init_int(&that->deleted, MTAPI_FALSE);
embb_atomic_store_int(&that->deleted, MTAPI_FALSE); embb_atomic_init_int(&that->num_tasks, 0);
embb_atomic_init_int(&that->num_tasks);
embb_atomic_store_int(&that->num_tasks, 0);
embb_mtapi_task_queue_initialize(&that->queue); embb_mtapi_task_queue_initialize(&that->queue);
} }
...@@ -69,10 +67,8 @@ void embb_mtapi_group_initialize_with_node( ...@@ -69,10 +67,8 @@ void embb_mtapi_group_initialize_with_node(
assert(MTAPI_NULL != node); assert(MTAPI_NULL != node);
that->group_id = MTAPI_GROUP_ID_NONE; that->group_id = MTAPI_GROUP_ID_NONE;
embb_atomic_init_int(&that->deleted); embb_atomic_init_int(&that->deleted, MTAPI_FALSE);
embb_atomic_store_int(&that->deleted, MTAPI_FALSE); embb_atomic_init_int(&that->num_tasks, 0);
embb_atomic_init_int(&that->num_tasks);
embb_atomic_store_int(&that->num_tasks, 0);
embb_mtapi_task_queue_initialize_with_capacity( embb_mtapi_task_queue_initialize_with_capacity(
&that->queue, node->attributes.queue_limit); &that->queue, node->attributes.queue_limit);
} }
......
...@@ -105,8 +105,7 @@ void mtapi_initialize( ...@@ -105,8 +105,7 @@ void mtapi_initialize(
} }
if (MTAPI_SUCCESS == local_status) { if (MTAPI_SUCCESS == local_status) {
embb_atomic_init_int(&node->is_scheduler_running); embb_atomic_init_int(&node->is_scheduler_running, MTAPI_FALSE);
embb_atomic_store_int(&node->is_scheduler_running, MTAPI_FALSE);
/* initialize storage */ /* initialize storage */
embb_mtapi_job_initialize_list(node); embb_mtapi_job_initialize_list(node);
......
...@@ -56,10 +56,8 @@ void embb_mtapi_queue_initialize(embb_mtapi_queue_t* that) { ...@@ -56,10 +56,8 @@ void embb_mtapi_queue_initialize(embb_mtapi_queue_t* that) {
mtapi_queueattr_init(&that->attributes, MTAPI_NULL); mtapi_queueattr_init(&that->attributes, MTAPI_NULL);
that->queue_id = MTAPI_QUEUE_ID_NONE; that->queue_id = MTAPI_QUEUE_ID_NONE;
embb_atomic_init_char(&that->enabled); embb_atomic_init_char(&that->enabled, MTAPI_FALSE);
embb_atomic_store_char(&that->enabled, MTAPI_FALSE); embb_atomic_init_int(&that->num_tasks, 0);
embb_atomic_init_int(&that->num_tasks);
embb_atomic_store_int(&that->num_tasks, 0);
that->job_handle.id = 0; that->job_handle.id = 0;
that->job_handle.tag = 0; that->job_handle.tag = 0;
} }
...@@ -73,10 +71,8 @@ void embb_mtapi_queue_initialize_with_attributes_and_job( ...@@ -73,10 +71,8 @@ void embb_mtapi_queue_initialize_with_attributes_and_job(
that->attributes = *attributes; that->attributes = *attributes;
that->queue_id = MTAPI_QUEUE_ID_NONE; that->queue_id = MTAPI_QUEUE_ID_NONE;
embb_atomic_init_char(&that->enabled); embb_atomic_init_char(&that->enabled, MTAPI_TRUE);
embb_atomic_store_char(&that->enabled, MTAPI_TRUE); embb_atomic_init_int(&that->num_tasks, 0);
embb_atomic_init_int(&that->num_tasks);
embb_atomic_store_int(&that->num_tasks, 0);
that->job_handle = job; that->job_handle = job;
} }
......
...@@ -473,8 +473,7 @@ mtapi_boolean_t embb_mtapi_scheduler_initialize_with_mode( ...@@ -473,8 +473,7 @@ mtapi_boolean_t embb_mtapi_scheduler_initialize_with_mode(
assert(MTAPI_NULL != that); assert(MTAPI_NULL != that);
assert(MTAPI_NULL != node); assert(MTAPI_NULL != node);
embb_atomic_init_int(&that->affine_task_counter); embb_atomic_init_int(&that->affine_task_counter, 0);
embb_atomic_store_int(&that->affine_task_counter, 0);
/* Paranoia sanitizing of scheduler mode */ /* Paranoia sanitizing of scheduler mode */
if (mode >= NUM_SCHEDULER_MODES) { if (mode >= NUM_SCHEDULER_MODES) {
......
...@@ -79,16 +79,14 @@ void embb_mtapi_task_initialize(embb_mtapi_task_t* that) { ...@@ -79,16 +79,14 @@ void embb_mtapi_task_initialize(embb_mtapi_task_t* that) {
that->action.id = EMBB_MTAPI_IDPOOL_INVALID_ID; that->action.id = EMBB_MTAPI_IDPOOL_INVALID_ID;
that->job.id = EMBB_MTAPI_IDPOOL_INVALID_ID; that->job.id = EMBB_MTAPI_IDPOOL_INVALID_ID;
embb_atomic_init_int(&that->state); embb_atomic_init_int(&that->state, MTAPI_TASK_ERROR);
embb_atomic_store_int(&that->state, MTAPI_TASK_ERROR);
that->task_id = MTAPI_TASK_ID_NONE; that->task_id = MTAPI_TASK_ID_NONE;
that->group.id = EMBB_MTAPI_IDPOOL_INVALID_ID; that->group.id = EMBB_MTAPI_IDPOOL_INVALID_ID;
that->queue.id = EMBB_MTAPI_IDPOOL_INVALID_ID; that->queue.id = EMBB_MTAPI_IDPOOL_INVALID_ID;
that->error_code = MTAPI_SUCCESS; that->error_code = MTAPI_SUCCESS;
embb_atomic_init_unsigned_int(&that->current_instance); embb_atomic_init_unsigned_int(&that->current_instance, 0);
embb_atomic_store_unsigned_int(&that->current_instance, 0);
embb_spin_init(&that->state_lock); embb_spin_init(&that->state_lock);
embb_atomic_init_unsigned_int(&that->instances_todo); embb_atomic_init_unsigned_int(&that->instances_todo, 0);
} }
void embb_mtapi_task_finalize(embb_mtapi_task_t* that) { void embb_mtapi_task_finalize(embb_mtapi_task_t* that) {
......
...@@ -59,11 +59,8 @@ mtapi_boolean_t embb_mtapi_thread_context_initialize( ...@@ -59,11 +59,8 @@ mtapi_boolean_t embb_mtapi_thread_context_initialize(
that->is_main_thread = (worker_index == 0) ? that->is_main_thread = (worker_index == 0) ?
node->attributes.reuse_main_thread : MTAPI_FALSE; node->attributes.reuse_main_thread : MTAPI_FALSE;
embb_atomic_init_int(&that->run); embb_atomic_init_int(&that->run, 0);
embb_atomic_init_int(&that->is_sleeping); embb_atomic_init_int(&that->is_sleeping, 0);
embb_atomic_store_int(&that->run, 0);
embb_atomic_store_int(&that->is_sleeping, 0);
that->queue = (embb_mtapi_task_queue_t**)embb_mtapi_alloc_allocate( that->queue = (embb_mtapi_task_queue_t**)embb_mtapi_alloc_allocate(
sizeof(embb_mtapi_task_queue_t)*that->priorities); sizeof(embb_mtapi_task_queue_t)*that->priorities);
......
...@@ -733,7 +733,7 @@ void TestContext() { ...@@ -733,7 +733,7 @@ void TestContext() {
} }
void ErrorTest::TestBasic() { void ErrorTest::TestBasic() {
embb_atomic_init_int(&wait); embb_atomic_init_int(&wait, 0);
TestNodeNotInit(); TestNodeNotInit();
TestParameter(); TestParameter();
......
...@@ -84,10 +84,8 @@ void plugin_initialize( ...@@ -84,10 +84,8 @@ void plugin_initialize(
plugin_task.id = 0; plugin_task.id = 0;
plugin_task.tag = 0; plugin_task.tag = 0;
embb_atomic_init_int(&plugin_running); embb_atomic_init_int(&plugin_running, 1);
embb_atomic_store_int(&plugin_running, 1); embb_atomic_init_int(&plugin_task_available, 0);
embb_atomic_init_int(&plugin_task_available);
embb_atomic_store_int(&plugin_task_available, 0);
err = embb_thread_create(&plugin_thread, NULL, plugin_thread_function, NULL); err = embb_thread_create(&plugin_thread, NULL, plugin_thread_function, NULL);
if (EMBB_SUCCESS == err) { if (EMBB_SUCCESS == err) {
......
...@@ -658,8 +658,7 @@ void mtapi_network_plugin_initialize( ...@@ -658,8 +658,7 @@ void mtapi_network_plugin_initialize(
err = embb_mtapi_network_initialize(); err = embb_mtapi_network_initialize();
if (0 == err) return; if (0 == err) return;
embb_atomic_init_int(&plugin->run); embb_atomic_init_int(&plugin->run, 0);
embb_atomic_store_int(&plugin->run, 0);
err = embb_mtapi_network_buffer_initialize( err = embb_mtapi_network_buffer_initialize(
&plugin->recv_buffer, (int)buffer_size); &plugin->recv_buffer, (int)buffer_size);
......
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