summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-06 06:44:41 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2016-05-12 13:24:40 +0200
commit6e4f929296b1cfd50fc8f41f117459e65214b816 (patch)
tree9819ea160f6c745dae1936ae296709026d3d47a2 /cpukit/score/src
parentscore: Add _Thread_queue_Is_lock_owner() (diff)
downloadrtems-6e4f929296b1cfd50fc8f41f117459e65214b816.tar.bz2
score: Introduce thread state lock
Update #2556.
Diffstat (limited to 'cpukit/score/src')
-rw-r--r--cpukit/score/src/thread.c1
-rw-r--r--cpukit/score/src/threaddispatch.c15
-rw-r--r--cpukit/score/src/threadinitialize.c2
-rw-r--r--cpukit/score/src/threadrestart.c44
4 files changed, 36 insertions, 26 deletions
diff --git a/cpukit/score/src/thread.c b/cpukit/score/src/thread.c
index 83e98cbab2..2e0bbd91bb 100644
--- a/cpukit/score/src/thread.c
+++ b/cpukit/score/src/thread.c
@@ -30,6 +30,7 @@
)
THREAD_OFFSET_ASSERT( Object );
+THREAD_OFFSET_ASSERT( Join_queue );
THREAD_OFFSET_ASSERT( current_state );
THREAD_OFFSET_ASSERT( current_priority );
THREAD_OFFSET_ASSERT( real_priority );
diff --git a/cpukit/score/src/threaddispatch.c b/cpukit/score/src/threaddispatch.c
index ce5d118a22..a1f4c54f93 100644
--- a/cpukit/score/src/threaddispatch.c
+++ b/cpukit/score/src/threaddispatch.c
@@ -9,7 +9,7 @@
* COPYRIGHT (c) 1989-2009.
* On-Line Applications Research Corporation (OAR).
*
- * Copyright (c) 2014 embedded brains GmbH.
+ * Copyright (c) 2014, 2016 embedded brains GmbH.
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
@@ -50,23 +50,22 @@ static Thread_Action *_Thread_Get_post_switch_action(
static void _Thread_Run_post_switch_actions( Thread_Control *executing )
{
- ISR_Level level;
- Per_CPU_Control *cpu_self;
- Thread_Action *action;
+ ISR_lock_Context lock_context;
+ Thread_Action *action;
- cpu_self = _Thread_Action_ISR_disable_and_acquire( executing, &level );
+ _Thread_State_acquire( executing, &lock_context );
action = _Thread_Get_post_switch_action( executing );
while ( action != NULL ) {
_Chain_Set_off_chain( &action->Node );
- ( *action->handler )( executing, action, cpu_self, level );
+ ( *action->handler )( executing, action, &lock_context );
- cpu_self = _Thread_Action_ISR_disable_and_acquire( executing, &level );
+ _Thread_State_acquire( executing, &lock_context );
action = _Thread_Get_post_switch_action( executing );
}
- _Thread_Action_release_and_ISR_enable( cpu_self, level );
+ _Thread_State_release( executing, &lock_context );
}
void _Thread_Do_dispatch( Per_CPU_Control *cpu_self, ISR_Level level )
diff --git a/cpukit/score/src/threadinitialize.c b/cpukit/score/src/threadinitialize.c
index c3e6469679..47d546e67e 100644
--- a/cpukit/score/src/threadinitialize.c
+++ b/cpukit/score/src/threadinitialize.c
@@ -190,6 +190,8 @@ bool _Thread_Initialize(
/* Initialize the CPU for the non-SMP schedulers */
_Thread_Set_CPU( the_thread, cpu );
+ _Thread_queue_Initialize( &the_thread->Join_queue );
+
the_thread->current_state = STATES_DORMANT;
the_thread->Wait.operations = &_Thread_queue_Operations_default;
the_thread->current_priority = priority;
diff --git a/cpukit/score/src/threadrestart.c b/cpukit/score/src/threadrestart.c
index 13b4365b35..ca054fab55 100644
--- a/cpukit/score/src/threadrestart.c
+++ b/cpukit/score/src/threadrestart.c
@@ -32,6 +32,12 @@
#include <rtems/score/watchdogimpl.h>
#include <rtems/score/wkspace.h>
+static void _Thread_Life_action_handler(
+ Thread_Control *executing,
+ Thread_Action *action,
+ ISR_lock_Context *lock_context
+);
+
typedef struct {
Chain_Control Chain;
ISR_lock_Control Lock;
@@ -133,6 +139,8 @@ static void _Thread_Free( Thread_Control *the_thread )
_SMP_lock_Stats_destroy( &the_thread->Potpourri_stats );
#endif
+ _Thread_queue_Destroy( &the_thread->Join_queue );
+
_Objects_Free( &information->Objects, &the_thread->Object );
}
@@ -179,11 +187,15 @@ static void _Thread_Add_life_change_action(
Thread_Control *the_thread
)
{
+ ISR_lock_Context lock_context;
+
+ _Thread_State_acquire( the_thread, &lock_context );
_Thread_Add_post_switch_action(
the_thread,
&the_thread->Life.Action,
_Thread_Life_action_handler
);
+ _Thread_State_release( the_thread, &lock_context );
}
static void _Thread_Start_life_change_for_executing(
@@ -202,10 +214,9 @@ static void _Thread_Start_life_change_for_executing(
}
void _Thread_Life_action_handler(
- Thread_Control *executing,
- Thread_Action *action,
- Per_CPU_Control *cpu,
- ISR_Level level
+ Thread_Control *executing,
+ Thread_Action *action,
+ ISR_lock_Context *lock_context
)
{
Thread_Life_state previous_life_state;
@@ -215,7 +226,7 @@ void _Thread_Life_action_handler(
previous_life_state = executing->Life.state;
executing->Life.state = THREAD_LIFE_PROTECTED;
- _Thread_Action_release_and_ISR_enable( cpu, level );
+ _Thread_State_release( executing, lock_context );
if ( _Thread_Is_life_terminating( previous_life_state ) ) {
_User_extensions_Thread_terminate( executing );
@@ -295,15 +306,14 @@ static void _Thread_Request_life_change(
Thread_Life_state additional_life_state
)
{
- Thread_Life_state previous_life_state;
- Per_CPU_Control *cpu;
- ISR_Level level;
+ Thread_Life_state previous_life_state;
+ ISR_lock_Context lock_context;
const Scheduler_Control *scheduler;
- cpu = _Thread_Action_ISR_disable_and_acquire( the_thread, &level );
+ _Thread_State_acquire( the_thread, &lock_context );
previous_life_state = the_thread->Life.state;
the_thread->Life.state = previous_life_state | additional_life_state;
- _Thread_Action_release_and_ISR_enable( cpu, level );
+ _Thread_State_release( the_thread, &lock_context );
scheduler = _Scheduler_Get( the_thread );
if ( the_thread == executing ) {
@@ -381,14 +391,12 @@ bool _Thread_Restart(
bool _Thread_Set_life_protection( bool protect )
{
- bool previous_life_protection;
- ISR_Level level;
- Per_CPU_Control *cpu;
- Thread_Control *executing;
- Thread_Life_state previous_life_state;
+ bool previous_life_protection;
+ ISR_lock_Context lock_context;
+ Thread_Control *executing;
+ Thread_Life_state previous_life_state;
- cpu = _Thread_Action_ISR_disable_and_acquire_for_executing( &level );
- executing = cpu->executing;
+ executing = _Thread_State_acquire_for_executing( &lock_context );
previous_life_state = executing->Life.state;
previous_life_protection = _Thread_Is_life_protected( previous_life_state );
@@ -399,7 +407,7 @@ bool _Thread_Set_life_protection( bool protect )
executing->Life.state = previous_life_state & ~THREAD_LIFE_PROTECTED;
}
- _Thread_Action_release_and_ISR_enable( cpu, level );
+ _Thread_State_release( executing, &lock_context );
#if defined(RTEMS_SMP)
/*