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
f670df71
authored
Feb 23, 2016
by
Marcus Winter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mtapi_c: fixed codesonar warnings
parent
ef7f44c1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
59 deletions
+131
-59
mtapi_c/src/embb_mtapi_node_t.c
+41
-27
mtapi_c/src/embb_mtapi_scheduler_t.c
+21
-11
mtapi_c/src/embb_mtapi_thread_context_t.c
+66
-20
mtapi_c/src/embb_mtapi_thread_context_t.h
+3
-1
No files found.
mtapi_c/src/embb_mtapi_node_t.c
View file @
f670df71
...
@@ -115,29 +115,33 @@ void mtapi_initialize(
...
@@ -115,29 +115,33 @@ void mtapi_initialize(
node
->
attributes
.
max_tasks
);
node
->
attributes
.
max_tasks
);
node
->
queue_pool
=
embb_mtapi_queue_pool_new
(
node
->
queue_pool
=
embb_mtapi_queue_pool_new
(
node
->
attributes
.
max_queues
);
node
->
attributes
.
max_queues
);
if
(
MTAPI_NULL
==
node
->
job_list
||
MTAPI_NULL
==
node
->
action_pool
||
MTAPI_NULL
==
node
->
group_pool
||
MTAPI_NULL
==
node
->
task_pool
||
MTAPI_NULL
==
node
->
queue_pool
)
{
mtapi_finalize
(
NULL
);
local_status
=
MTAPI_ERR_NODE_INITFAILED
;
}
/* initialize scheduler for local node */
if
(
local_status
==
MTAPI_SUCCESS
)
{
node
->
scheduler
=
embb_mtapi_scheduler_new
();
/* initialize scheduler for local node */
if
(
MTAPI_NULL
!=
node
->
scheduler
)
{
node
->
scheduler
=
embb_mtapi_scheduler_new
();
/* fill information structure */
if
(
MTAPI_NULL
!=
node
->
scheduler
)
{
node
->
info
.
hardware_concurrency
=
embb_core_count_available
();
/* fill information structure */
node
->
info
.
used_memory
=
embb_mtapi_alloc_get_bytes_allocated
();
node
->
info
.
hardware_concurrency
=
embb_core_count_available
();
if
(
MTAPI_NULL
!=
mtapi_info
)
{
node
->
info
.
used_memory
=
embb_mtapi_alloc_get_bytes_allocated
();
*
mtapi_info
=
node
->
info
;
if
(
MTAPI_NULL
!=
mtapi_info
)
{
}
*
mtapi_info
=
node
->
info
;
}
/* initialization succeeded, tell workers to start working */
embb_atomic_store_int
(
&
node
->
is_scheduler_running
,
MTAPI_TRUE
);
/* initialization succeeded, tell workers to start working */
embb_atomic_store_int
(
&
node
->
is_scheduler_running
,
MTAPI_TRUE
);
if
(
MTAPI_SUCCESS
!=
local_status
)
{
}
else
{
mtapi_finalize
(
MTAPI_NULL
);
mtapi_finalize
(
MTAPI_NULL
);
local_status
=
MTAPI_ERR_NODE_INITFAILED
;
local_status
=
MTAPI_ERR_NODE_INITFAILED
;
}
}
}
else
{
mtapi_finalize
(
MTAPI_NULL
);
local_status
=
MTAPI_ERR_NODE_INITFAILED
;
}
}
}
else
{
}
else
{
embb_mtapi_alloc_deallocate
(
node
);
embb_mtapi_alloc_deallocate
(
node
);
local_status
=
MTAPI_ERR_PARAMETER
;
local_status
=
MTAPI_ERR_PARAMETER
;
...
@@ -163,19 +167,29 @@ void mtapi_finalize(MTAPI_OUT mtapi_status_t* status) {
...
@@ -163,19 +167,29 @@ void mtapi_finalize(MTAPI_OUT mtapi_status_t* status) {
}
}
/* finalize storage in reverse order */
/* finalize storage in reverse order */
embb_mtapi_queue_pool_delete
(
node
->
queue_pool
);
if
(
MTAPI_NULL
!=
node
->
queue_pool
)
{
node
->
queue_pool
=
MTAPI_NULL
;
embb_mtapi_queue_pool_delete
(
node
->
queue_pool
);
node
->
queue_pool
=
MTAPI_NULL
;
}
embb_mtapi_task_pool_delete
(
node
->
task_pool
);
if
(
MTAPI_NULL
!=
node
->
task_pool
)
{
node
->
task_pool
=
MTAPI_NULL
;
embb_mtapi_task_pool_delete
(
node
->
task_pool
);
node
->
task_pool
=
MTAPI_NULL
;
}
embb_mtapi_group_pool_delete
(
node
->
group_pool
);
if
(
MTAPI_NULL
!=
node
->
group_pool
)
{
node
->
group_pool
=
MTAPI_NULL
;
embb_mtapi_group_pool_delete
(
node
->
group_pool
);
node
->
group_pool
=
MTAPI_NULL
;
}
embb_mtapi_action_pool_delete
(
node
->
action_pool
);
if
(
MTAPI_NULL
!=
node
->
action_pool
)
{
node
->
action_pool
=
MTAPI_NULL
;
embb_mtapi_action_pool_delete
(
node
->
action_pool
);
node
->
action_pool
=
MTAPI_NULL
;
}
embb_mtapi_job_finalize_list
(
node
);
if
(
MTAPI_NULL
!=
node
->
job_list
)
{
embb_mtapi_job_finalize_list
(
node
);
}
/* free system instance */
/* free system instance */
embb_mtapi_alloc_deallocate
(
node
);
embb_mtapi_alloc_deallocate
(
node
);
...
...
mtapi_c/src/embb_mtapi_scheduler_t.c
View file @
f670df71
...
@@ -456,6 +456,10 @@ mtapi_boolean_t embb_mtapi_scheduler_initialize_with_mode(
...
@@ -456,6 +456,10 @@ mtapi_boolean_t embb_mtapi_scheduler_initialize_with_mode(
that
->
worker_contexts
=
(
embb_mtapi_thread_context_t
*
)
that
->
worker_contexts
=
(
embb_mtapi_thread_context_t
*
)
embb_mtapi_alloc_allocate
(
embb_mtapi_alloc_allocate
(
sizeof
(
embb_mtapi_thread_context_t
)
*
that
->
worker_count
);
sizeof
(
embb_mtapi_thread_context_t
)
*
that
->
worker_count
);
if
(
NULL
==
that
->
worker_contexts
)
{
return
MTAPI_FALSE
;
}
mtapi_boolean_t
isinit
=
MTAPI_TRUE
;
for
(
ii
=
0
;
ii
<
that
->
worker_count
;
ii
++
)
{
for
(
ii
=
0
;
ii
<
that
->
worker_count
;
ii
++
)
{
unsigned
int
core_num
=
0
;
unsigned
int
core_num
=
0
;
mtapi_uint_t
ll
=
0
;
mtapi_uint_t
ll
=
0
;
...
@@ -467,9 +471,12 @@ mtapi_boolean_t embb_mtapi_scheduler_initialize_with_mode(
...
@@ -467,9 +471,12 @@ mtapi_boolean_t embb_mtapi_scheduler_initialize_with_mode(
}
}
core_num
++
;
core_num
++
;
}
}
embb_mtapi_thread_context_initialize_with_node_worker_and_core
(
isinit
&=
embb_mtapi_thread_context_initialize_with_node_worker_and_core
(
&
that
->
worker_contexts
[
ii
],
node
,
ii
,
core_num
);
&
that
->
worker_contexts
[
ii
],
node
,
ii
,
core_num
);
}
}
if
(
!
isinit
)
{
return
MTAPI_FALSE
;
}
for
(
ii
=
0
;
ii
<
that
->
worker_count
;
ii
++
)
{
for
(
ii
=
0
;
ii
<
that
->
worker_count
;
ii
++
)
{
if
(
MTAPI_FALSE
==
embb_mtapi_thread_context_start
(
if
(
MTAPI_FALSE
==
embb_mtapi_thread_context_start
(
&
that
->
worker_contexts
[
ii
],
that
))
{
&
that
->
worker_contexts
[
ii
],
that
))
{
...
@@ -486,17 +493,19 @@ void embb_mtapi_scheduler_finalize(embb_mtapi_scheduler_t * that) {
...
@@ -486,17 +493,19 @@ void embb_mtapi_scheduler_finalize(embb_mtapi_scheduler_t * that) {
assert
(
MTAPI_NULL
!=
that
);
assert
(
MTAPI_NULL
!=
that
);
/* finalize all workers */
if
(
MTAPI_NULL
!=
that
->
worker_contexts
)
{
for
(
ii
=
0
;
ii
<
that
->
worker_count
;
ii
++
)
{
/* finalize all workers */
embb_mtapi_thread_context_stop
(
&
that
->
worker_contexts
[
ii
]);
for
(
ii
=
0
;
ii
<
that
->
worker_count
;
ii
++
)
{
}
embb_mtapi_thread_context_stop
(
&
that
->
worker_contexts
[
ii
]);
for
(
ii
=
0
;
ii
<
that
->
worker_count
;
ii
++
)
{
}
embb_mtapi_thread_context_finalize
(
&
that
->
worker_contexts
[
ii
]);
for
(
ii
=
0
;
ii
<
that
->
worker_count
;
ii
++
)
{
}
embb_mtapi_thread_context_finalize
(
&
that
->
worker_contexts
[
ii
]);
}
that
->
worker_count
=
0
;
that
->
worker_count
=
0
;
embb_mtapi_alloc_deallocate
(
that
->
worker_contexts
);
embb_mtapi_alloc_deallocate
(
that
->
worker_contexts
);
that
->
worker_contexts
=
MTAPI_NULL
;
that
->
worker_contexts
=
MTAPI_NULL
;
}
}
}
embb_mtapi_scheduler_t
*
embb_mtapi_scheduler_new
()
{
embb_mtapi_scheduler_t
*
embb_mtapi_scheduler_new
()
{
...
@@ -506,6 +515,7 @@ embb_mtapi_scheduler_t * embb_mtapi_scheduler_new() {
...
@@ -506,6 +515,7 @@ embb_mtapi_scheduler_t * embb_mtapi_scheduler_new() {
if
(
MTAPI_NULL
!=
that
)
{
if
(
MTAPI_NULL
!=
that
)
{
if
(
MTAPI_FALSE
==
embb_mtapi_scheduler_initialize
(
that
))
{
if
(
MTAPI_FALSE
==
embb_mtapi_scheduler_initialize
(
that
))
{
/* on error delete and return MTAPI_NULL */
/* on error delete and return MTAPI_NULL */
embb_mtapi_scheduler_finalize
(
that
);
embb_mtapi_scheduler_delete
(
that
);
embb_mtapi_scheduler_delete
(
that
);
return
MTAPI_NULL
;
return
MTAPI_NULL
;
}
}
...
...
mtapi_c/src/embb_mtapi_thread_context_t.c
View file @
f670df71
...
@@ -38,12 +38,13 @@
...
@@ -38,12 +38,13 @@
/* ---- CLASS MEMBERS ------------------------------------------------------ */
/* ---- CLASS MEMBERS ------------------------------------------------------ */
void
embb_mtapi_thread_context_initialize_with_node_worker_and_core
(
mtapi_boolean_t
embb_mtapi_thread_context_initialize_with_node_worker_and_core
(
embb_mtapi_thread_context_t
*
that
,
embb_mtapi_thread_context_t
*
that
,
embb_mtapi_node_t
*
node
,
embb_mtapi_node_t
*
node
,
mtapi_uint_t
worker_index
,
mtapi_uint_t
worker_index
,
mtapi_uint_t
core_num
)
{
mtapi_uint_t
core_num
)
{
mtapi_uint_t
ii
;
mtapi_uint_t
ii
;
mtapi_boolean_t
result
=
MTAPI_TRUE
;
assert
(
MTAPI_NULL
!=
that
);
assert
(
MTAPI_NULL
!=
that
);
assert
(
MTAPI_NULL
!=
node
);
assert
(
MTAPI_NULL
!=
node
);
...
@@ -52,25 +53,55 @@ void embb_mtapi_thread_context_initialize_with_node_worker_and_core(
...
@@ -52,25 +53,55 @@ void embb_mtapi_thread_context_initialize_with_node_worker_and_core(
that
->
worker_index
=
worker_index
;
that
->
worker_index
=
worker_index
;
that
->
core_num
=
core_num
;
that
->
core_num
=
core_num
;
that
->
priorities
=
node
->
attributes
.
max_priorities
;
that
->
priorities
=
node
->
attributes
.
max_priorities
;
that
->
is_initialized
=
MTAPI_FALSE
;
embb_atomic_store_int
(
&
that
->
run
,
0
);
embb_atomic_store_int
(
&
that
->
run
,
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
);
that
->
private_queue
=
(
embb_mtapi_task_queue_t
**
)
embb_mtapi_alloc_allocate
(
if
(
that
->
queue
==
NULL
)
{
sizeof
(
embb_mtapi_task_queue_t
)
*
that
->
priorities
);
that
->
private_queue
=
NULL
;
return
MTAPI_FALSE
;
}
for
(
ii
=
0
;
ii
<
that
->
priorities
;
ii
++
)
{
for
(
ii
=
0
;
ii
<
that
->
priorities
;
ii
++
)
{
that
->
queue
[
ii
]
=
(
embb_mtapi_task_queue_t
*
)
that
->
queue
[
ii
]
=
(
embb_mtapi_task_queue_t
*
)
embb_mtapi_alloc_allocate
(
sizeof
(
embb_mtapi_task_queue_t
));
embb_mtapi_alloc_allocate
(
sizeof
(
embb_mtapi_task_queue_t
));
embb_mtapi_task_queue_initialize_with_capacity
(
if
(
that
->
queue
[
ii
]
!=
NULL
)
{
that
->
queue
[
ii
],
node
->
attributes
.
queue_limit
);
embb_mtapi_task_queue_initialize_with_capacity
(
that
->
queue
[
ii
],
node
->
attributes
.
queue_limit
);
}
else
{
result
=
MTAPI_FALSE
;
}
}
if
(
!
result
)
{
return
MTAPI_FALSE
;
}
that
->
private_queue
=
(
embb_mtapi_task_queue_t
**
)
embb_mtapi_alloc_allocate
(
sizeof
(
embb_mtapi_task_queue_t
)
*
that
->
priorities
);
if
(
that
->
private_queue
==
NULL
)
{
return
MTAPI_FALSE
;
}
for
(
ii
=
0
;
ii
<
that
->
priorities
;
ii
++
)
{
that
->
private_queue
[
ii
]
=
(
embb_mtapi_task_queue_t
*
)
that
->
private_queue
[
ii
]
=
(
embb_mtapi_task_queue_t
*
)
embb_mtapi_alloc_allocate
(
sizeof
(
embb_mtapi_task_queue_t
));
embb_mtapi_alloc_allocate
(
sizeof
(
embb_mtapi_task_queue_t
));
embb_mtapi_task_queue_initialize_with_capacity
(
if
(
that
->
private_queue
[
ii
]
!=
NULL
)
{
that
->
private_queue
[
ii
],
node
->
attributes
.
queue_limit
);
embb_mtapi_task_queue_initialize_with_capacity
(
that
->
private_queue
[
ii
],
node
->
attributes
.
queue_limit
);
}
else
{
result
=
MTAPI_FALSE
;
}
}
if
(
!
result
)
{
return
MTAPI_FALSE
;
}
}
embb_mutex_init
(
&
that
->
work_available_mutex
,
EMBB_MUTEX_PLAIN
);
embb_mutex_init
(
&
that
->
work_available_mutex
,
EMBB_MUTEX_PLAIN
);
embb_condition_init
(
&
that
->
work_available
);
embb_condition_init
(
&
that
->
work_available
);
embb_atomic_store_int
(
&
that
->
is_sleeping
,
0
);
embb_atomic_store_int
(
&
that
->
is_sleeping
,
0
);
that
->
is_initialized
=
MTAPI_TRUE
;
return
MTAPI_TRUE
;
}
}
mtapi_boolean_t
embb_mtapi_thread_context_start
(
mtapi_boolean_t
embb_mtapi_thread_context_start
(
...
@@ -126,22 +157,37 @@ void embb_mtapi_thread_context_finalize(embb_mtapi_thread_context_t* that) {
...
@@ -126,22 +157,37 @@ void embb_mtapi_thread_context_finalize(embb_mtapi_thread_context_t* that) {
embb_mtapi_log_trace
(
"embb_mtapi_thread_context_finalize() called
\n
"
);
embb_mtapi_log_trace
(
"embb_mtapi_thread_context_finalize() called
\n
"
);
embb_condition_destroy
(
&
that
->
work_available
);
if
(
that
->
is_initialized
)
{
embb_mutex_destroy
(
&
that
->
work_available_mutex
);
embb_condition_destroy
(
&
that
->
work_available
);
embb_mutex_destroy
(
&
that
->
work_available_mutex
);
}
for
(
ii
=
0
;
ii
<
that
->
priorities
;
ii
++
)
{
if
(
that
->
queue
!=
NULL
)
{
embb_mtapi_task_queue_finalize
(
that
->
queue
[
ii
]);
for
(
ii
=
0
;
ii
<
that
->
priorities
;
ii
++
)
{
embb_mtapi_alloc_deallocate
(
that
->
queue
[
ii
]);
if
(
that
->
queue
[
ii
]
!=
NULL
)
{
that
->
queue
[
ii
]
=
MTAPI_NULL
;
embb_mtapi_task_queue_finalize
(
that
->
queue
[
ii
]);
embb_mtapi_task_queue_finalize
(
that
->
private_queue
[
ii
]);
embb_mtapi_alloc_deallocate
(
that
->
queue
[
ii
]);
embb_mtapi_alloc_deallocate
(
that
->
private_queue
[
ii
]);
that
->
queue
[
ii
]
=
MTAPI_NULL
;
that
->
private_queue
[
ii
]
=
MTAPI_NULL
;
}
}
embb_mtapi_alloc_deallocate
(
that
->
queue
);
that
->
queue
=
MTAPI_NULL
;
}
}
embb_mtapi_alloc_deallocate
(
that
->
queue
);
that
->
queue
=
MTAPI_NULL
;
if
(
that
->
private_queue
!=
NULL
)
{
embb_mtapi_alloc_deallocate
(
that
->
private_queue
);
for
(
ii
=
0
;
ii
<
that
->
priorities
;
ii
++
)
{
that
->
private_queue
=
MTAPI_NULL
;
if
(
that
->
private_queue
[
ii
]
!=
NULL
)
{
embb_mtapi_task_queue_finalize
(
that
->
private_queue
[
ii
]);
embb_mtapi_alloc_deallocate
(
that
->
private_queue
[
ii
]);
that
->
private_queue
[
ii
]
=
MTAPI_NULL
;
}
}
embb_mtapi_alloc_deallocate
(
that
->
private_queue
);
that
->
private_queue
=
MTAPI_NULL
;
}
that
->
priorities
=
0
;
that
->
priorities
=
0
;
that
->
is_initialized
=
MTAPI_FALSE
;
that
->
node
=
MTAPI_NULL
;
that
->
node
=
MTAPI_NULL
;
}
}
...
...
mtapi_c/src/embb_mtapi_thread_context_t.h
View file @
f670df71
...
@@ -67,6 +67,7 @@ struct embb_mtapi_thread_context_struct {
...
@@ -67,6 +67,7 @@ struct embb_mtapi_thread_context_struct {
mtapi_uint_t
core_num
;
mtapi_uint_t
core_num
;
embb_atomic_int
run
;
embb_atomic_int
run
;
mtapi_status_t
status
;
mtapi_status_t
status
;
mtapi_boolean_t
is_initialized
;
};
};
#include <embb_mtapi_thread_context_t_fwd.h>
#include <embb_mtapi_thread_context_t_fwd.h>
...
@@ -74,8 +75,9 @@ struct embb_mtapi_thread_context_struct {
...
@@ -74,8 +75,9 @@ struct embb_mtapi_thread_context_struct {
/**
/**
* Constructor using attributes from node and a given core number.
* Constructor using attributes from node and a given core number.
* \memberof embb_mtapi_thread_context_struct
* \memberof embb_mtapi_thread_context_struct
* \returns MTAPI_TRUE if successful, MTAPI_FALSE on error
*/
*/
void
embb_mtapi_thread_context_initialize_with_node_worker_and_core
(
mtapi_boolean_t
embb_mtapi_thread_context_initialize_with_node_worker_and_core
(
embb_mtapi_thread_context_t
*
that
,
embb_mtapi_thread_context_t
*
that
,
embb_mtapi_node_t
*
node
,
embb_mtapi_node_t
*
node
,
mtapi_uint_t
worker_index
,
mtapi_uint_t
worker_index
,
...
...
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