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
a002d5af
authored
9 years ago
by
Christian Kern
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace mtapi spinlock usage with embb spinlocks
parent
1c8c0ec5
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
27 additions
and
33 deletions
+27
-33
mtapi_c/src/embb_mtapi_id_pool_t.c
+7
-6
mtapi_c/src/embb_mtapi_id_pool_t.h
+2
-3
mtapi_c/src/embb_mtapi_node_t.c
+0
-6
mtapi_c/src/embb_mtapi_queue_t.h
+1
-1
mtapi_c/src/embb_mtapi_task_queue_t.c
+9
-9
mtapi_c/src/embb_mtapi_task_queue_t.h
+2
-2
mtapi_c/src/embb_mtapi_task_t.c
+4
-4
mtapi_c/src/embb_mtapi_task_t.h
+2
-2
No files found.
mtapi_c/src/embb_mtapi_id_pool_t.c
View file @
a002d5af
...
@@ -29,6 +29,7 @@
...
@@ -29,6 +29,7 @@
#include <embb_mtapi_alloc.h>
#include <embb_mtapi_alloc.h>
#include <embb_mtapi_log.h>
#include <embb_mtapi_log.h>
#include <embb_mtapi_id_pool_t.h>
#include <embb_mtapi_id_pool_t.h>
#include <embb/base/c/mutex.h>
void
embb_mtapi_id_pool_initialize
(
void
embb_mtapi_id_pool_initialize
(
embb_mtapi_id_pool_t
*
that
,
embb_mtapi_id_pool_t
*
that
,
...
@@ -45,7 +46,7 @@ void embb_mtapi_id_pool_initialize(
...
@@ -45,7 +46,7 @@ void embb_mtapi_id_pool_initialize(
that
->
ids_available
=
capacity
;
that
->
ids_available
=
capacity
;
that
->
put_id_position
=
0
;
that
->
put_id_position
=
0
;
that
->
get_id_position
=
1
;
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
)
{
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) {
...
@@ -55,7 +56,7 @@ void embb_mtapi_id_pool_finalize(embb_mtapi_id_pool_t * that) {
that
->
put_id_position
=
0
;
that
->
put_id_position
=
0
;
embb_mtapi_alloc_deallocate
(
that
->
id_buffer
);
embb_mtapi_alloc_deallocate
(
that
->
id_buffer
);
that
->
id_buffer
=
NULL
;
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
)
{
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) {
...
@@ -63,7 +64,7 @@ mtapi_uint_t embb_mtapi_id_pool_allocate(embb_mtapi_id_pool_t * that) {
assert
(
MTAPI_NULL
!=
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
)
{
if
(
0
<
that
->
ids_available
)
{
/* take away one id */
/* take away one id */
that
->
ids_available
--
;
that
->
ids_available
--
;
...
@@ -81,7 +82,7 @@ mtapi_uint_t embb_mtapi_id_pool_allocate(embb_mtapi_id_pool_t * that) {
...
@@ -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 */
/* make id entry invalid just in case */
that
->
id_buffer
[
id_position
]
=
EMBB_MTAPI_IDPOOL_INVALID_ID
;
that
->
id_buffer
[
id_position
]
=
EMBB_MTAPI_IDPOOL_INVALID_ID
;
}
}
embb_
mtapi_spinlock_release
(
&
that
->
lock
);
embb_
spin_unlock
(
&
that
->
lock
);
}
}
return
id
;
return
id
;
...
@@ -92,7 +93,7 @@ void embb_mtapi_id_pool_deallocate(
...
@@ -92,7 +93,7 @@ void embb_mtapi_id_pool_deallocate(
mtapi_uint_t
id
)
{
mtapi_uint_t
id
)
{
assert
(
MTAPI_NULL
!=
that
);
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
)
{
if
(
that
->
capacity
>
that
->
ids_available
)
{
/* acquire position to put id to */
/* acquire position to put id to */
mtapi_uint_t
id_position
=
that
->
put_id_position
;
mtapi_uint_t
id_position
=
that
->
put_id_position
;
...
@@ -107,7 +108,7 @@ void embb_mtapi_id_pool_deallocate(
...
@@ -107,7 +108,7 @@ void embb_mtapi_id_pool_deallocate(
/* make it available */
/* make it available */
that
->
ids_available
++
;
that
->
ids_available
++
;
}
}
embb_
mtapi_spinlock_release
(
&
that
->
lock
);
embb_
spin_unlock
(
&
that
->
lock
);
}
else
{
}
else
{
embb_mtapi_log_error
(
embb_mtapi_log_error
(
"could not acquire lock in embb_mtapi_IdPool_deallocate
\n
"
);
"could not acquire lock in embb_mtapi_IdPool_deallocate
\n
"
);
...
...
This diff is collapsed.
Click to expand it.
mtapi_c/src/embb_mtapi_id_pool_t.h
View file @
a002d5af
...
@@ -29,8 +29,7 @@
...
@@ -29,8 +29,7 @@
#include <embb/mtapi/c/mtapi.h>
#include <embb/mtapi/c/mtapi.h>
#include <embb/base/c/atomic.h>
#include <embb/base/c/atomic.h>
#include <embb/base/c/mutex.h>
#include <embb_mtapi_spinlock_t.h>
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
@@ -51,7 +50,7 @@ struct embb_mtapi_id_pool_struct {
...
@@ -51,7 +50,7 @@ struct embb_mtapi_id_pool_struct {
mtapi_uint_t
ids_available
;
mtapi_uint_t
ids_available
;
mtapi_uint_t
get_id_position
;
mtapi_uint_t
get_id_position
;
mtapi_uint_t
put_id_position
;
mtapi_uint_t
put_id_position
;
embb_
mtapi_
spinlock_t
lock
;
embb_spinlock_t
lock
;
};
};
/**
/**
...
...
This diff is collapsed.
Click to expand it.
mtapi_c/src/embb_mtapi_node_t.c
View file @
a002d5af
...
@@ -41,7 +41,6 @@
...
@@ -41,7 +41,6 @@
static
embb_mtapi_node_t
*
embb_mtapi_node_instance
=
NULL
;
static
embb_mtapi_node_t
*
embb_mtapi_node_instance
=
NULL
;
extern
embb_atomic_int
embb_mtapi_spinlock_spins
;
/* ---- CLASS MEMBERS ------------------------------------------------------ */
/* ---- CLASS MEMBERS ------------------------------------------------------ */
...
@@ -87,8 +86,6 @@ void mtapi_initialize(
...
@@ -87,8 +86,6 @@ void mtapi_initialize(
/* out of memory! */
/* out of memory! */
local_status
=
MTAPI_ERR_UNKNOWN
;
local_status
=
MTAPI_ERR_UNKNOWN
;
}
else
{
}
else
{
embb_atomic_store_int
(
&
embb_mtapi_spinlock_spins
,
0
);
node
=
embb_mtapi_node_instance
;
node
=
embb_mtapi_node_instance
;
node
->
domain_id
=
domain_id
;
node
->
domain_id
=
domain_id
;
...
@@ -184,9 +181,6 @@ void mtapi_finalize(MTAPI_OUT mtapi_status_t* status) {
...
@@ -184,9 +181,6 @@ void mtapi_finalize(MTAPI_OUT mtapi_status_t* status) {
embb_mtapi_alloc_deallocate
(
node
);
embb_mtapi_alloc_deallocate
(
node
);
embb_mtapi_node_instance
=
MTAPI_NULL
;
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
;
local_status
=
MTAPI_SUCCESS
;
}
else
{
}
else
{
local_status
=
MTAPI_ERR_NODE_NOTINIT
;
local_status
=
MTAPI_ERR_NODE_NOTINIT
;
...
...
This diff is collapsed.
Click to expand it.
mtapi_c/src/embb_mtapi_queue_t.h
View file @
a002d5af
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
#include <embb/base/c/atomic.h>
#include <embb/base/c/atomic.h>
#include <embb_mtapi_pool_template.h>
#include <embb_mtapi_pool_template.h>
#include <embb
_mtapi_spinlock_t
.h>
#include <embb
/base/c/mutex
.h>
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
...
This diff is collapsed.
Click to expand it.
mtapi_c/src/embb_mtapi_task_queue_t.c
View file @
a002d5af
...
@@ -46,7 +46,7 @@ void embb_mtapi_task_queue_initialize(embb_mtapi_task_queue_t* that) {
...
@@ -46,7 +46,7 @@ void embb_mtapi_task_queue_initialize(embb_mtapi_task_queue_t* that) {
that
->
get_task_position
=
0
;
that
->
get_task_position
=
0
;
that
->
put_task_position
=
0
;
that
->
put_task_position
=
0
;
mtapi_queueattr_init
(
&
that
->
attributes
,
MTAPI_NULL
);
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
(
void
embb_mtapi_task_queue_initialize_with_capacity
(
...
@@ -61,7 +61,7 @@ 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
;
that
->
put_task_position
=
0
;
mtapi_queueattr_init
(
&
that
->
attributes
,
MTAPI_NULL
);
mtapi_queueattr_init
(
&
that
->
attributes
,
MTAPI_NULL
);
that
->
attributes
.
limit
=
capacity
;
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
)
{
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) {
...
@@ -70,7 +70,7 @@ void embb_mtapi_task_queue_finalize(embb_mtapi_task_queue_t* that) {
embb_mtapi_task_queue_initialize
(
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
)
{
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) {
...
@@ -78,7 +78,7 @@ embb_mtapi_task_t * embb_mtapi_task_queue_pop(embb_mtapi_task_queue_t* that) {
assert
(
MTAPI_NULL
!=
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
)
{
if
(
0
<
that
->
tasks_available
)
{
/* take away one task */
/* take away one task */
that
->
tasks_available
--
;
that
->
tasks_available
--
;
...
@@ -96,7 +96,7 @@ embb_mtapi_task_t * embb_mtapi_task_queue_pop(embb_mtapi_task_queue_t* that) {
...
@@ -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 */
/* make task entry invalid just in case */
that
->
task_buffer
[
task_position
]
=
MTAPI_NULL
;
that
->
task_buffer
[
task_position
]
=
MTAPI_NULL
;
}
}
embb_
mtapi_spinlock_release
(
&
that
->
lock
);
embb_
spin_unlock
(
&
that
->
lock
);
}
}
return
task
;
return
task
;
...
@@ -109,7 +109,7 @@ mtapi_boolean_t embb_mtapi_task_queue_push(
...
@@ -109,7 +109,7 @@ mtapi_boolean_t embb_mtapi_task_queue_push(
assert
(
MTAPI_NULL
!=
that
);
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
)
{
if
(
that
->
attributes
.
limit
>
that
->
tasks_available
)
{
/* acquire position to put task into */
/* acquire position to put task into */
mtapi_uint_t
task_position
=
that
->
put_task_position
;
mtapi_uint_t
task_position
=
that
->
put_task_position
;
...
@@ -126,7 +126,7 @@ mtapi_boolean_t embb_mtapi_task_queue_push(
...
@@ -126,7 +126,7 @@ mtapi_boolean_t embb_mtapi_task_queue_push(
result
=
MTAPI_TRUE
;
result
=
MTAPI_TRUE
;
}
}
embb_
mtapi_spinlock_release
(
&
that
->
lock
);
embb_
spin_unlock
(
&
that
->
lock
);
}
}
return
result
;
return
result
;
...
@@ -143,7 +143,7 @@ mtapi_boolean_t embb_mtapi_task_queue_process(
...
@@ -143,7 +143,7 @@ mtapi_boolean_t embb_mtapi_task_queue_process(
assert
(
MTAPI_NULL
!=
that
);
assert
(
MTAPI_NULL
!=
that
);
assert
(
MTAPI_NULL
!=
process
);
assert
(
MTAPI_NULL
!=
process
);
if
(
embb_
mtapi_spinlock_acquire
(
&
that
->
lock
)
)
{
if
(
embb_
spin_lock
(
&
that
->
lock
)
==
EMBB_SUCCESS
)
{
idx
=
that
->
get_task_position
;
idx
=
that
->
get_task_position
;
for
(
ii
=
0
;
ii
<
that
->
tasks_available
;
ii
++
)
{
for
(
ii
=
0
;
ii
<
that
->
tasks_available
;
ii
++
)
{
result
=
process
(
that
->
task_buffer
[
ii
],
user_data
);
result
=
process
(
that
->
task_buffer
[
ii
],
user_data
);
...
@@ -152,7 +152,7 @@ mtapi_boolean_t embb_mtapi_task_queue_process(
...
@@ -152,7 +152,7 @@ mtapi_boolean_t embb_mtapi_task_queue_process(
}
}
idx
=
(
idx
+
1
)
%
that
->
attributes
.
limit
;
idx
=
(
idx
+
1
)
%
that
->
attributes
.
limit
;
}
}
embb_
mtapi_spinlock_release
(
&
that
->
lock
);
embb_
spin_unlock
(
&
that
->
lock
);
}
}
return
result
;
return
result
;
...
...
This diff is collapsed.
Click to expand it.
mtapi_c/src/embb_mtapi_task_queue_t.h
View file @
a002d5af
...
@@ -30,7 +30,7 @@
...
@@ -30,7 +30,7 @@
#include <embb/mtapi/c/mtapi.h>
#include <embb/mtapi/c/mtapi.h>
#include <embb/base/c/atomic.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>
#include <embb_mtapi_task_visitor_function_t.h>
#ifdef __cplusplus
#ifdef __cplusplus
...
@@ -57,7 +57,7 @@ struct embb_mtapi_task_queue_struct {
...
@@ -57,7 +57,7 @@ struct embb_mtapi_task_queue_struct {
mtapi_uint_t
get_task_position
;
mtapi_uint_t
get_task_position
;
mtapi_uint_t
put_task_position
;
mtapi_uint_t
put_task_position
;
mtapi_queue_attributes_t
attributes
;
mtapi_queue_attributes_t
attributes
;
embb_
mtapi_
spinlock_t
lock
;
embb_spinlock_t
lock
;
};
};
#include <embb_mtapi_task_queue_t_fwd.h>
#include <embb_mtapi_task_queue_t_fwd.h>
...
...
This diff is collapsed.
Click to expand it.
mtapi_c/src/embb_mtapi_task_t.c
View file @
a002d5af
...
@@ -85,14 +85,14 @@ void embb_mtapi_task_initialize(embb_mtapi_task_t* that) {
...
@@ -85,14 +85,14 @@ void embb_mtapi_task_initialize(embb_mtapi_task_t* that) {
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_store_unsigned_int
(
&
that
->
current_instance
,
0
);
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
)
{
void
embb_mtapi_task_finalize
(
embb_mtapi_task_t
*
that
)
{
assert
(
MTAPI_NULL
!=
that
);
assert
(
MTAPI_NULL
!=
that
);
embb_mtapi_task_initialize
(
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
(
mtapi_boolean_t
embb_mtapi_task_execute
(
...
@@ -158,10 +158,10 @@ void embb_mtapi_task_set_state(
...
@@ -158,10 +158,10 @@ void embb_mtapi_task_set_state(
mtapi_task_state_t
state
)
{
mtapi_task_state_t
state
)
{
assert
(
MTAPI_NULL
!=
that
);
assert
(
MTAPI_NULL
!=
that
);
embb_
mtapi_spinlock_acquire
(
&
that
->
state_lock
);
embb_
spin_lock
(
&
that
->
state_lock
);
that
->
state
=
state
;
that
->
state
=
state
;
embb_atomic_memory_barrier
();
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
(
static
mtapi_task_hndl_t
embb_mtapi_task_start
(
...
...
This diff is collapsed.
Click to expand it.
mtapi_c/src/embb_mtapi_task_t.h
View file @
a002d5af
...
@@ -31,7 +31,7 @@
...
@@ -31,7 +31,7 @@
#include <embb/base/c/atomic.h>
#include <embb/base/c/atomic.h>
#include <embb_mtapi_pool_template.h>
#include <embb_mtapi_pool_template.h>
#include <embb
_mtapi_spinlock_t
.h>
#include <embb
/base/c/mutex
.h>
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
@@ -65,7 +65,7 @@ struct embb_mtapi_task_struct {
...
@@ -65,7 +65,7 @@ struct embb_mtapi_task_struct {
mtapi_queue_hndl_t
queue
;
mtapi_queue_hndl_t
queue
;
mtapi_action_hndl_t
action
;
mtapi_action_hndl_t
action
;
embb_
mtapi_
spinlock_t
state_lock
;
embb_spinlock_t
state_lock
;
volatile
mtapi_task_state_t
state
;
volatile
mtapi_task_state_t
state
;
embb_atomic_unsigned_int
current_instance
;
embb_atomic_unsigned_int
current_instance
;
embb_atomic_unsigned_int
instances_todo
;
embb_atomic_unsigned_int
instances_todo
;
...
...
This diff is collapsed.
Click to expand it.
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