Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
FORMUS3IC_LAS3
/
embb
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
f58e653a
authored
Nov 07, 2016
by
Marcus Winter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
base_c: atomic initialization check in debug mode, atomic initialization with value
parent
61caf1ab
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
69 additions
and
54 deletions
+69
-54
base_c/include/embb/base/c/atomic.h
+10
-2
base_c/include/embb/base/c/internal/atomic/atomic_variables.h
+30
-0
base_c/include/embb/base/c/internal/atomic/init.h
+4
-1
base_c/src/counter.c
+1
-2
base_c/src/mutex.c
+1
-4
base_c/test/thread_index_test.cc
+1
-2
mtapi_c/src/embb_mtapi_action_plugin_t.c
+1
-2
mtapi_c/src/embb_mtapi_action_t.c
+2
-4
mtapi_c/src/embb_mtapi_group_t.c
+4
-8
mtapi_c/src/embb_mtapi_node_t.c
+1
-2
mtapi_c/src/embb_mtapi_queue_t.c
+4
-8
mtapi_c/src/embb_mtapi_scheduler_t.c
+1
-2
mtapi_c/src/embb_mtapi_task_t.c
+3
-5
mtapi_c/src/embb_mtapi_thread_context_t.c
+2
-5
mtapi_c/test/embb_mtapi_test_error.cc
+1
-1
mtapi_c/test/embb_mtapi_test_plugin.cc
+2
-4
mtapi_plugins_c/mtapi_network_c/src/embb_mtapi_network.c
+1
-2
No files found.
base_c/include/embb/base/c/atomic.h
View file @
f58e653a
...
...
@@ -320,8 +320,6 @@ void embb_mutex_destroy(
#define EMBB_ATOMIC_MUTEX_LOCK(mutex) embb_mutex_lock(&(mutex))
#define EMBB_ATOMIC_MUTEX_UNLOCK(mutex) embb_mutex_unlock(&(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
...
...
@@ -329,6 +327,16 @@ void embb_mutex_destroy(
#define EMBB_ATOMIC_MUTEX_LOCK(...)
#define EMBB_ATOMIC_MUTEX_UNLOCK(...)
#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_MARKER(variable) (void)(variable)
...
...
base_c/include/embb/base/c/internal/atomic/atomic_variables.h
View file @
f58e653a
...
...
@@ -35,6 +35,8 @@
#include <intrin.h>
#endif
#ifdef EMBB_DEBUG
#ifdef EMBB_THREADING_ANALYSIS_MODE
#define EMBB_ATOMIC_INTERNAL_DEFINE_VARIABLE( \
...
...
@@ -55,10 +57,38 @@
typedef struct \
{ \
volatile EMBB_ATOMIC_PARAMETER_TYPE_NATIVE internal_variable; \
uint32_t marker; \
} EMBB_CAT2(embb_atomic_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX);
#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
(
short
,
short
)
EMBB_ATOMIC_INTERNAL_DEFINE_VARIABLE
(
unsigned
short
,
unsigned_short
)
...
...
base_c/include/embb/base/c/internal/atomic/init.h
View file @
f58e653a
...
...
@@ -33,6 +33,7 @@
#include <embb/base/c/internal/atomic/atomic_sizes.h>
#include <embb/base/c/internal/macro_helper.h>
#include <embb/base/c/internal/atomic/atomic_variables.h>
#include <embb/base/c/internal/atomic/store.h>
#include <string.h>
/*
...
...
@@ -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) \
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_INIT_MARKER(variable); \
EMBB_CAT2(embb_atomic_store_, EMBB_ATOMIC_PARAMETER_ATOMIC_TYPE_SUFFIX)(variable, value); \
}
#undef EMBB_ATOMIC_METHOD_TO_GENERATE
...
...
base_c/src/counter.c
View file @
f58e653a
...
...
@@ -33,8 +33,7 @@ int embb_counter_init(embb_counter_t* counter) {
if
(
counter
==
NULL
)
{
return
EMBB_ERROR
;
}
embb_atomic_init_unsigned_int
(
&
(
counter
->
value
));
embb_atomic_store_unsigned_int
(
&
(
counter
->
value
),
0
);
embb_atomic_init_unsigned_int
(
&
(
counter
->
value
),
0
);
return
EMBB_SUCCESS
;
}
...
...
base_c/src/mutex.c
View file @
f58e653a
...
...
@@ -147,10 +147,7 @@ int embb_spin_init(embb_spinlock_t* spinlock) {
if
(
NULL
==
spinlock
)
{
return
EMBB_ERROR
;
}
// For now, store the initial value. In the future will use atomic init
// function (as soon as available).
embb_atomic_init_int
(
&
spinlock
->
atomic_spin_variable_
);
embb_atomic_store_int
(
&
spinlock
->
atomic_spin_variable_
,
0
);
embb_atomic_init_int
(
&
spinlock
->
atomic_spin_variable_
,
0
);
return
EMBB_SUCCESS
;
}
...
...
base_c/test/thread_index_test.cc
View file @
f58e653a
...
...
@@ -40,8 +40,7 @@ embb_atomic_int flag;
ThreadIndexTest
::
ThreadIndexTest
()
:
number_threads_
(
partest
::
TestSuite
::
GetDefaultNumThreads
())
{
embb_atomic_init_int
(
&
flag
);
embb_atomic_store_int
(
&
flag
,
1
);
embb_atomic_init_int
(
&
flag
,
1
);
CreateUnit
(
"Test 0 indices"
).
Add
(
&
ThreadIndexTest
::
Test0
,
this
);
CreateUnit
(
"Test 1 index"
).
Add
(
&
ThreadIndexTest
::
Test1
,
this
);
...
...
mtapi_c/src/embb_mtapi_action_plugin_t.c
View file @
f58e653a
...
...
@@ -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
->
enabled
=
MTAPI_TRUE
;
new_action
->
is_plugin_action
=
MTAPI_TRUE
;
embb_atomic_init_int
(
&
new_action
->
num_tasks
);
embb_atomic_store_int
(
&
new_action
->
num_tasks
,
0
);
embb_atomic_init_int
(
&
new_action
->
num_tasks
,
0
);
new_action
->
plugin_task_start_function
=
task_start_function
;
new_action
->
plugin_task_cancel_function
=
task_cancel_function
;
...
...
mtapi_c/src/embb_mtapi_action_t.c
View file @
f58e653a
...
...
@@ -59,8 +59,7 @@ void embb_mtapi_action_initialize(embb_mtapi_action_t* that) {
that
->
node_local_data
=
NULL
;
that
->
node_local_data_size
=
0
;
that
->
plugin_data
=
MTAPI_NULL
;
embb_atomic_init_int
(
&
that
->
num_tasks
);
embb_atomic_store_int
(
&
that
->
num_tasks
,
0
);
embb_atomic_init_int
(
&
that
->
num_tasks
,
0
);
}
void
embb_mtapi_action_finalize
(
embb_mtapi_action_t
*
that
)
{
...
...
@@ -153,8 +152,7 @@ mtapi_action_hndl_t mtapi_action_create(
new_action
->
node_local_data_size
=
node_local_data_size
;
new_action
->
enabled
=
MTAPI_TRUE
;
new_action
->
is_plugin_action
=
MTAPI_FALSE
;
embb_atomic_init_int
(
&
new_action
->
num_tasks
);
embb_atomic_store_int
(
&
new_action
->
num_tasks
,
0
);
embb_atomic_init_int
(
&
new_action
->
num_tasks
,
0
);
new_action
->
action_function
=
action_function
;
...
...
mtapi_c/src/embb_mtapi_group_t.c
View file @
f58e653a
...
...
@@ -55,10 +55,8 @@ void embb_mtapi_group_initialize(embb_mtapi_group_t * that) {
assert
(
MTAPI_NULL
!=
that
);
that
->
group_id
=
MTAPI_GROUP_ID_NONE
;
embb_atomic_init_int
(
&
that
->
deleted
);
embb_atomic_store_int
(
&
that
->
deleted
,
MTAPI_FALSE
);
embb_atomic_init_int
(
&
that
->
num_tasks
);
embb_atomic_store_int
(
&
that
->
num_tasks
,
0
);
embb_atomic_init_int
(
&
that
->
deleted
,
MTAPI_FALSE
);
embb_atomic_init_int
(
&
that
->
num_tasks
,
0
);
embb_mtapi_task_queue_initialize
(
&
that
->
queue
);
}
...
...
@@ -69,10 +67,8 @@ void embb_mtapi_group_initialize_with_node(
assert
(
MTAPI_NULL
!=
node
);
that
->
group_id
=
MTAPI_GROUP_ID_NONE
;
embb_atomic_init_int
(
&
that
->
deleted
);
embb_atomic_store_int
(
&
that
->
deleted
,
MTAPI_FALSE
);
embb_atomic_init_int
(
&
that
->
num_tasks
);
embb_atomic_store_int
(
&
that
->
num_tasks
,
0
);
embb_atomic_init_int
(
&
that
->
deleted
,
MTAPI_FALSE
);
embb_atomic_init_int
(
&
that
->
num_tasks
,
0
);
embb_mtapi_task_queue_initialize_with_capacity
(
&
that
->
queue
,
node
->
attributes
.
queue_limit
);
}
...
...
mtapi_c/src/embb_mtapi_node_t.c
View file @
f58e653a
...
...
@@ -105,8 +105,7 @@ void mtapi_initialize(
}
if
(
MTAPI_SUCCESS
==
local_status
)
{
embb_atomic_init_int
(
&
node
->
is_scheduler_running
);
embb_atomic_store_int
(
&
node
->
is_scheduler_running
,
MTAPI_FALSE
);
embb_atomic_init_int
(
&
node
->
is_scheduler_running
,
MTAPI_FALSE
);
/* initialize storage */
embb_mtapi_job_initialize_list
(
node
);
...
...
mtapi_c/src/embb_mtapi_queue_t.c
View file @
f58e653a
...
...
@@ -56,10 +56,8 @@ void embb_mtapi_queue_initialize(embb_mtapi_queue_t* that) {
mtapi_queueattr_init
(
&
that
->
attributes
,
MTAPI_NULL
);
that
->
queue_id
=
MTAPI_QUEUE_ID_NONE
;
embb_atomic_init_char
(
&
that
->
enabled
);
embb_atomic_store_char
(
&
that
->
enabled
,
MTAPI_FALSE
);
embb_atomic_init_int
(
&
that
->
num_tasks
);
embb_atomic_store_int
(
&
that
->
num_tasks
,
0
);
embb_atomic_init_char
(
&
that
->
enabled
,
MTAPI_FALSE
);
embb_atomic_init_int
(
&
that
->
num_tasks
,
0
);
that
->
job_handle
.
id
=
0
;
that
->
job_handle
.
tag
=
0
;
}
...
...
@@ -73,10 +71,8 @@ void embb_mtapi_queue_initialize_with_attributes_and_job(
that
->
attributes
=
*
attributes
;
that
->
queue_id
=
MTAPI_QUEUE_ID_NONE
;
embb_atomic_init_char
(
&
that
->
enabled
);
embb_atomic_store_char
(
&
that
->
enabled
,
MTAPI_TRUE
);
embb_atomic_init_int
(
&
that
->
num_tasks
);
embb_atomic_store_int
(
&
that
->
num_tasks
,
0
);
embb_atomic_init_char
(
&
that
->
enabled
,
MTAPI_TRUE
);
embb_atomic_init_int
(
&
that
->
num_tasks
,
0
);
that
->
job_handle
=
job
;
}
...
...
mtapi_c/src/embb_mtapi_scheduler_t.c
View file @
f58e653a
...
...
@@ -473,8 +473,7 @@ mtapi_boolean_t embb_mtapi_scheduler_initialize_with_mode(
assert
(
MTAPI_NULL
!=
that
);
assert
(
MTAPI_NULL
!=
node
);
embb_atomic_init_int
(
&
that
->
affine_task_counter
);
embb_atomic_store_int
(
&
that
->
affine_task_counter
,
0
);
embb_atomic_init_int
(
&
that
->
affine_task_counter
,
0
);
/* Paranoia sanitizing of scheduler mode */
if
(
mode
>=
NUM_SCHEDULER_MODES
)
{
...
...
mtapi_c/src/embb_mtapi_task_t.c
View file @
f58e653a
...
...
@@ -79,16 +79,14 @@ void embb_mtapi_task_initialize(embb_mtapi_task_t* that) {
that
->
action
.
id
=
EMBB_MTAPI_IDPOOL_INVALID_ID
;
that
->
job
.
id
=
EMBB_MTAPI_IDPOOL_INVALID_ID
;
embb_atomic_init_int
(
&
that
->
state
);
embb_atomic_store_int
(
&
that
->
state
,
MTAPI_TASK_ERROR
);
embb_atomic_init_int
(
&
that
->
state
,
MTAPI_TASK_ERROR
);
that
->
task_id
=
MTAPI_TASK_ID_NONE
;
that
->
group
.
id
=
EMBB_MTAPI_IDPOOL_INVALID_ID
;
that
->
queue
.
id
=
EMBB_MTAPI_IDPOOL_INVALID_ID
;
that
->
error_code
=
MTAPI_SUCCESS
;
embb_atomic_init_unsigned_int
(
&
that
->
current_instance
);
embb_atomic_store_unsigned_int
(
&
that
->
current_instance
,
0
);
embb_atomic_init_unsigned_int
(
&
that
->
current_instance
,
0
);
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
)
{
...
...
mtapi_c/src/embb_mtapi_thread_context_t.c
View file @
f58e653a
...
...
@@ -59,11 +59,8 @@ mtapi_boolean_t embb_mtapi_thread_context_initialize(
that
->
is_main_thread
=
(
worker_index
==
0
)
?
node
->
attributes
.
reuse_main_thread
:
MTAPI_FALSE
;
embb_atomic_init_int
(
&
that
->
run
);
embb_atomic_init_int
(
&
that
->
is_sleeping
);
embb_atomic_store_int
(
&
that
->
run
,
0
);
embb_atomic_store_int
(
&
that
->
is_sleeping
,
0
);
embb_atomic_init_int
(
&
that
->
run
,
0
);
embb_atomic_init_int
(
&
that
->
is_sleeping
,
0
);
that
->
queue
=
(
embb_mtapi_task_queue_t
**
)
embb_mtapi_alloc_allocate
(
sizeof
(
embb_mtapi_task_queue_t
)
*
that
->
priorities
);
...
...
mtapi_c/test/embb_mtapi_test_error.cc
View file @
f58e653a
...
...
@@ -733,7 +733,7 @@ void TestContext() {
}
void
ErrorTest
::
TestBasic
()
{
embb_atomic_init_int
(
&
wait
);
embb_atomic_init_int
(
&
wait
,
0
);
TestNodeNotInit
();
TestParameter
();
...
...
mtapi_c/test/embb_mtapi_test_plugin.cc
View file @
f58e653a
...
...
@@ -84,10 +84,8 @@ void plugin_initialize(
plugin_task
.
id
=
0
;
plugin_task
.
tag
=
0
;
embb_atomic_init_int
(
&
plugin_running
);
embb_atomic_store_int
(
&
plugin_running
,
1
);
embb_atomic_init_int
(
&
plugin_task_available
);
embb_atomic_store_int
(
&
plugin_task_available
,
0
);
embb_atomic_init_int
(
&
plugin_running
,
1
);
embb_atomic_init_int
(
&
plugin_task_available
,
0
);
err
=
embb_thread_create
(
&
plugin_thread
,
NULL
,
plugin_thread_function
,
NULL
);
if
(
EMBB_SUCCESS
==
err
)
{
...
...
mtapi_plugins_c/mtapi_network_c/src/embb_mtapi_network.c
View file @
f58e653a
...
...
@@ -658,8 +658,7 @@ void mtapi_network_plugin_initialize(
err
=
embb_mtapi_network_initialize
();
if
(
0
==
err
)
return
;
embb_atomic_init_int
(
&
plugin
->
run
);
embb_atomic_store_int
(
&
plugin
->
run
,
0
);
embb_atomic_init_int
(
&
plugin
->
run
,
0
);
err
=
embb_mtapi_network_buffer_initialize
(
&
plugin
->
recv_buffer
,
(
int
)
buffer_size
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment