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
6328800f
authored
May 02, 2016
by
Marcus Winter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mtapi_c: reuse main thread
parent
1fe6f342
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
12 deletions
+31
-12
mtapi_c/src/embb_mtapi_thread_context_t.c
+30
-12
mtapi_c/src/embb_mtapi_thread_context_t.h
+1
-0
No files found.
mtapi_c/src/embb_mtapi_thread_context_t.c
View file @
6328800f
...
@@ -54,6 +54,7 @@ mtapi_boolean_t embb_mtapi_thread_context_initialize_with_node_worker_and_core(
...
@@ -54,6 +54,7 @@ mtapi_boolean_t embb_mtapi_thread_context_initialize_with_node_worker_and_core(
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
;
that
->
is_initialized
=
MTAPI_FALSE
;
that
->
is_main_thread
=
(
worker_index
==
0
)
?
MTAPI_TRUE
:
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
(
...
@@ -121,17 +122,29 @@ mtapi_boolean_t embb_mtapi_thread_context_start(
...
@@ -121,17 +122,29 @@ mtapi_boolean_t embb_mtapi_thread_context_start(
embb_core_set_add
(
&
core_set
,
that
->
core_num
);
embb_core_set_add
(
&
core_set
,
that
->
core_num
);
/* create thread */
/* create thread */
err
=
embb_thread_create
(
&
that
->
thread
,
&
core_set
,
worker_func
,
that
);
if
(
that
->
is_main_thread
)
{
if
(
EMBB_SUCCESS
!=
err
)
{
/* reuse main thread */
embb_mtapi_log_error
(
that
->
thread
=
embb_thread_current
();
"embb_mtapi_ThreadContext_initializeWithNodeAndCoreNumber() could not "
err
=
embb_tss_create
(
&
that
->
tss_id
);
"create thread %d on core %d
\n
"
,
that
->
worker_index
,
that
->
core_num
);
if
(
EMBB_SUCCESS
!=
err
)
{
return
MTAPI_FALSE
;
/* report error to scheduler */
}
embb_atomic_store_int
(
&
that
->
run
,
-
1
);
return
MTAPI_FALSE
;
/* wait for worker to come up */
}
while
(
0
==
embb_atomic_load_int
(
&
that
->
run
))
{
embb_tss_set
(
&
(
that
->
tss_id
),
that
);
embb_thread_yield
();
embb_atomic_store_int
(
&
that
->
run
,
1
);
}
else
{
err
=
embb_thread_create
(
&
that
->
thread
,
&
core_set
,
worker_func
,
that
);
if
(
EMBB_SUCCESS
!=
err
)
{
embb_mtapi_log_error
(
"embb_mtapi_ThreadContext_initializeWithNodeAndCoreNumber() could not "
"create thread %d on core %d
\n
"
,
that
->
worker_index
,
that
->
core_num
);
return
MTAPI_FALSE
;
}
/* wait for worker to come up */
while
(
0
==
embb_atomic_load_int
(
&
that
->
run
))
{
embb_thread_yield
();
}
}
}
if
(
0
<
embb_atomic_load_int
(
&
that
->
run
))
{
if
(
0
<
embb_atomic_load_int
(
&
that
->
run
))
{
...
@@ -146,7 +159,9 @@ void embb_mtapi_thread_context_stop(embb_mtapi_thread_context_t* that) {
...
@@ -146,7 +159,9 @@ void embb_mtapi_thread_context_stop(embb_mtapi_thread_context_t* that) {
if
(
0
<
embb_atomic_load_int
(
&
that
->
run
))
{
if
(
0
<
embb_atomic_load_int
(
&
that
->
run
))
{
embb_atomic_store_int
(
&
that
->
run
,
0
);
embb_atomic_store_int
(
&
that
->
run
,
0
);
embb_condition_notify_one
(
&
that
->
work_available
);
embb_condition_notify_one
(
&
that
->
work_available
);
embb_thread_join
(
&
(
that
->
thread
),
&
result
);
if
(
MTAPI_FALSE
==
that
->
is_main_thread
)
{
embb_thread_join
(
&
(
that
->
thread
),
&
result
);
}
}
}
}
}
...
@@ -158,6 +173,9 @@ void embb_mtapi_thread_context_finalize(embb_mtapi_thread_context_t* that) {
...
@@ -158,6 +173,9 @@ 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
"
);
if
(
that
->
is_initialized
)
{
if
(
that
->
is_initialized
)
{
if
(
that
->
is_main_thread
)
{
embb_tss_delete
(
&
that
->
tss_id
);
}
embb_condition_destroy
(
&
that
->
work_available
);
embb_condition_destroy
(
&
that
->
work_available
);
embb_mutex_destroy
(
&
that
->
work_available_mutex
);
embb_mutex_destroy
(
&
that
->
work_available_mutex
);
}
}
...
...
mtapi_c/src/embb_mtapi_thread_context_t.h
View file @
6328800f
...
@@ -68,6 +68,7 @@ struct embb_mtapi_thread_context_struct {
...
@@ -68,6 +68,7 @@ struct embb_mtapi_thread_context_struct {
embb_atomic_int
run
;
embb_atomic_int
run
;
mtapi_status_t
status
;
mtapi_status_t
status
;
mtapi_boolean_t
is_initialized
;
mtapi_boolean_t
is_initialized
;
mtapi_boolean_t
is_main_thread
;
};
};
#include <embb_mtapi_thread_context_t_fwd.h>
#include <embb_mtapi_thread_context_t_fwd.h>
...
...
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