summaryrefslogtreecommitdiffstats
path: root/cpukit/score
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2013-07-17 15:53:17 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2013-07-18 09:58:58 +0200
commit95e09afa92c5d0522a0d04019ef6680796688896 (patch)
tree2c04a60ed5669b4baba5a783e1919b4b4a37d858 /cpukit/score
parentscore: Convert to inline function (diff)
downloadrtems-95e09afa92c5d0522a0d04019ef6680796688896.tar.bz2
score: Avoid direct usage of _Thread_Executing
Pass the executing thread as a function parameter. Obtain the executing thread inside a thread dispatch critical section to avoid problems on SMP.
Diffstat (limited to 'cpukit/score')
-rw-r--r--cpukit/score/include/rtems/score/coremuteximpl.h35
-rw-r--r--cpukit/score/src/apimutexallocate.c2
-rw-r--r--cpukit/score/src/apimutexlock.c1
-rw-r--r--cpukit/score/src/coremutex.c15
-rw-r--r--cpukit/score/src/coremutexseize.c13
-rw-r--r--cpukit/score/src/coremutexseizeintr.c7
6 files changed, 47 insertions, 26 deletions
diff --git a/cpukit/score/include/rtems/score/coremuteximpl.h b/cpukit/score/include/rtems/score/coremuteximpl.h
index c35c0f3050..67e7c99e7a 100644
--- a/cpukit/score/include/rtems/score/coremuteximpl.h
+++ b/cpukit/score/include/rtems/score/coremuteximpl.h
@@ -110,7 +110,8 @@ typedef enum {
*
* This routine initializes the mutex based on the parameters passed.
*
- * @param[in] the_mutex is the mutex to initalize
+ * @param[in,out] the_mutex is the mutex to initalize
+ * @param[in,out] executing The currently executing thread.
* @param[in] the_mutex_attributes is the attributes associated with this
* mutex instance
* @param[in] initial_lock is the initial value of the mutex
@@ -119,7 +120,8 @@ typedef enum {
*/
CORE_mutex_Status _CORE_mutex_Initialize(
CORE_mutex_Control *the_mutex,
- CORE_mutex_Attributes *the_mutex_attributes,
+ Thread_Control *executing,
+ const CORE_mutex_Attributes *the_mutex_attributes,
uint32_t initial_lock
);
@@ -131,7 +133,8 @@ CORE_mutex_Status _CORE_mutex_Initialize(
* returns. Otherwise, the calling task is blocked until a unit becomes
* available.
*
- * @param[in] the_mutex is the mutex to attempt to lock
+ * @param[in,out] executing The currently executing thread.
+ * @param[in,out] the_mutex is the mutex to attempt to lock
* @param[in] level is the interrupt level
*
* @retval This routine returns 0 if "trylock" can resolve whether or not
@@ -145,6 +148,7 @@ CORE_mutex_Status _CORE_mutex_Initialize(
RTEMS_INLINE_ROUTINE int _CORE_mutex_Seize_interrupt_trylock_body(
CORE_mutex_Control *the_mutex,
+ Thread_Control *executing,
ISR_Level level
);
@@ -162,6 +166,7 @@ RTEMS_INLINE_ROUTINE int _CORE_mutex_Seize_interrupt_trylock_body(
*/
int _CORE_mutex_Seize_interrupt_trylock(
CORE_mutex_Control *the_mutex,
+ Thread_Control *executing,
ISR_Level level
);
#else
@@ -172,8 +177,8 @@ RTEMS_INLINE_ROUTINE int _CORE_mutex_Seize_interrupt_trylock_body(
* @param[in] _mutex will attempt to lock
* @param[in] _level is the interrupt level
*/
- #define _CORE_mutex_Seize_interrupt_trylock( _mutex, _level ) \
- _CORE_mutex_Seize_interrupt_trylock_body( _mutex, _level )
+ #define _CORE_mutex_Seize_interrupt_trylock( _mutex, _executing, _level ) \
+ _CORE_mutex_Seize_interrupt_trylock_body( _mutex, _executing, _level )
#endif
/**
@@ -183,11 +188,13 @@ RTEMS_INLINE_ROUTINE int _CORE_mutex_Seize_interrupt_trylock_body(
* It is an actual subroutine and is not implemented as something
* that may be inlined.
*
- * @param[in] the_mutex is the mutex to attempt to lock
+ * @param[in,out] the_mutex is the mutex to attempt to lock
+ * @param[in,out] executing The currently executing thread.
* @param[in] timeout is the maximum number of ticks to block
*/
void _CORE_mutex_Seize_interrupt_blocking(
CORE_mutex_Control *the_mutex,
+ Thread_Control *executing,
Watchdog_Interval timeout
);
/**
@@ -237,6 +244,7 @@ void _CORE_mutex_Seize_interrupt_blocking(
*/
RTEMS_INLINE_ROUTINE void _CORE_mutex_Seize_body(
CORE_mutex_Control *the_mutex,
+ Thread_Control *executing,
Objects_Id id,
bool wait,
Watchdog_Interval timeout,
@@ -250,7 +258,7 @@ RTEMS_INLINE_ROUTINE void _CORE_mutex_Seize_body(
INTERNAL_ERROR_MUTEX_OBTAIN_FROM_BAD_STATE
);
}
- if ( _CORE_mutex_Seize_interrupt_trylock( the_mutex, level ) ) {
+ if ( _CORE_mutex_Seize_interrupt_trylock( the_mutex, executing, level ) ) {
if ( !wait ) {
_ISR_Enable( level );
_Thread_Executing->Wait.return_code =
@@ -261,7 +269,7 @@ RTEMS_INLINE_ROUTINE void _CORE_mutex_Seize_body(
_Thread_Executing->Wait.id = id;
_Thread_Disable_dispatch();
_ISR_Enable( level );
- _CORE_mutex_Seize_interrupt_blocking( the_mutex, timeout );
+ _CORE_mutex_Seize_interrupt_blocking( the_mutex, executing, timeout );
}
}
}
@@ -279,14 +287,15 @@ RTEMS_INLINE_ROUTINE void _CORE_mutex_Seize_body(
#if defined(__RTEMS_DO_NOT_INLINE_CORE_MUTEX_SEIZE__)
void _CORE_mutex_Seize(
CORE_mutex_Control *_the_mutex,
+ Thread_Control *_executing,
Objects_Id _id,
bool _wait,
Watchdog_Interval _timeout,
ISR_Level _level
);
#else
- #define _CORE_mutex_Seize( _the_mutex, _id, _wait, _timeout, _level ) \
- _CORE_mutex_Seize_body( _the_mutex, _id, _wait, _timeout, _level )
+ #define _CORE_mutex_Seize( _executing, _mtx, _id, _wait, _timeout, _level ) \
+ _CORE_mutex_Seize_body( _executing, _mtx, _id, _wait, _timeout, _level )
#endif
/**
@@ -357,7 +366,7 @@ RTEMS_INLINE_ROUTINE bool _CORE_mutex_Is_locked(
* @retval false The mutex is not using FIFO blocking order.
*/
RTEMS_INLINE_ROUTINE bool _CORE_mutex_Is_fifo(
- CORE_mutex_Attributes *the_attribute
+ const CORE_mutex_Attributes *the_attribute
)
{
return the_attribute->discipline == CORE_MUTEX_DISCIPLINES_FIFO;
@@ -429,14 +438,12 @@ RTEMS_INLINE_ROUTINE bool _CORE_mutex_Is_priority_ceiling(
RTEMS_INLINE_ROUTINE int _CORE_mutex_Seize_interrupt_trylock_body(
CORE_mutex_Control *the_mutex,
+ Thread_Control *executing,
ISR_Level level
)
{
- Thread_Control *executing;
-
/* disabled when you get here */
- executing = _Thread_Executing;
executing->Wait.return_code = CORE_MUTEX_STATUS_SUCCESSFUL;
if ( !_CORE_mutex_Is_locked( the_mutex ) ) {
the_mutex->lock = CORE_MUTEX_LOCKED;
diff --git a/cpukit/score/src/apimutexallocate.c b/cpukit/score/src/apimutexallocate.c
index a736e2b14f..c57cc66e6b 100644
--- a/cpukit/score/src/apimutexallocate.c
+++ b/cpukit/score/src/apimutexallocate.c
@@ -37,7 +37,7 @@ void _API_Mutex_Allocate(
mutex = (API_Mutex_Control *) _Objects_Allocate( &_API_Mutex_Information );
- _CORE_mutex_Initialize( &mutex->Mutex, &attr, CORE_MUTEX_UNLOCKED );
+ _CORE_mutex_Initialize( &mutex->Mutex, NULL, &attr, CORE_MUTEX_UNLOCKED );
_Objects_Open_u32( &_API_Mutex_Information, &mutex->Object, 1 );
diff --git a/cpukit/score/src/apimutexlock.c b/cpukit/score/src/apimutexlock.c
index c5a2e42cc5..b6d957f84c 100644
--- a/cpukit/score/src/apimutexlock.c
+++ b/cpukit/score/src/apimutexlock.c
@@ -37,6 +37,7 @@ void _API_Mutex_Lock(
_CORE_mutex_Seize(
&the_mutex->Mutex,
+ _Thread_Executing,
the_mutex->Object.id,
true,
0,
diff --git a/cpukit/score/src/coremutex.c b/cpukit/score/src/coremutex.c
index a39b4efebf..8ea7d13a4d 100644
--- a/cpukit/score/src/coremutex.c
+++ b/cpukit/score/src/coremutex.c
@@ -27,7 +27,8 @@
CORE_mutex_Status _CORE_mutex_Initialize(
CORE_mutex_Control *the_mutex,
- CORE_mutex_Attributes *the_mutex_attributes,
+ Thread_Control *executing,
+ const CORE_mutex_Attributes *the_mutex_attributes,
uint32_t initial_lock
)
{
@@ -43,21 +44,21 @@ CORE_mutex_Status _CORE_mutex_Initialize(
if ( initial_lock == CORE_MUTEX_LOCKED ) {
the_mutex->nest_count = 1;
- the_mutex->holder = _Thread_Executing;
- the_mutex->holder_id = _Thread_Executing->Object.id;
+ the_mutex->holder = executing;
+ the_mutex->holder_id = executing->Object.id;
if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
- if ( _Thread_Executing->current_priority <
+ if ( executing->current_priority <
the_mutex->Attributes.priority_ceiling )
return CORE_MUTEX_STATUS_CEILING_VIOLATED;
#ifdef __RTEMS_STRICT_ORDER_MUTEX__
- _Chain_Prepend_unprotected( &_Thread_Executing->lock_mutex,
+ _Chain_Prepend_unprotected( &executing->lock_mutex,
&the_mutex->queue.lock_queue );
- the_mutex->queue.priority_before = _Thread_Executing->current_priority;
+ the_mutex->queue.priority_before = executing->current_priority;
#endif
- _Thread_Executing->resource_count++;
+ executing->resource_count++;
}
} else {
the_mutex->nest_count = 0;
diff --git a/cpukit/score/src/coremutexseize.c b/cpukit/score/src/coremutexseize.c
index 098d6f2472..3da513a77b 100644
--- a/cpukit/score/src/coremutexseize.c
+++ b/cpukit/score/src/coremutexseize.c
@@ -28,24 +28,31 @@
#if defined(__RTEMS_DO_NOT_INLINE_CORE_MUTEX_SEIZE__)
void _CORE_mutex_Seize(
CORE_mutex_Control *_the_mutex,
+ Thread_Control *_executing,
Objects_Id _id,
bool _wait,
Watchdog_Interval _timeout,
ISR_Level _level
)
{
- _CORE_mutex_Seize_body( _the_mutex, _id, _wait, _timeout, _level );
+ _CORE_mutex_Seize_body(
+ _the_mutex,
+ _executing,
+ _id,
+ _wait,
+ _timeout,
+ _level
+ );
}
#endif
void _CORE_mutex_Seize_interrupt_blocking(
CORE_mutex_Control *the_mutex,
+ Thread_Control *executing,
Watchdog_Interval timeout
)
{
- Thread_Control *executing;
- executing = _Thread_Executing;
if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ) {
if ( _Scheduler_Is_priority_higher_than(
executing->current_priority,
diff --git a/cpukit/score/src/coremutexseizeintr.c b/cpukit/score/src/coremutexseizeintr.c
index f31d2fba96..cc726b6135 100644
--- a/cpukit/score/src/coremutexseizeintr.c
+++ b/cpukit/score/src/coremutexseizeintr.c
@@ -28,9 +28,14 @@
#if defined(__RTEMS_DO_NOT_INLINE_CORE_MUTEX_SEIZE__)
int _CORE_mutex_Seize_interrupt_trylock(
CORE_mutex_Control *the_mutex,
+ Thread_Control *executing,
ISR_Level level
)
{
- return _CORE_mutex_Seize_interrupt_trylock_body( the_mutex, level );
+ return _CORE_mutex_Seize_interrupt_trylock_body(
+ the_mutex,
+ executing,
+ level
+ );
}
#endif