summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/coremutexsurrender.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2010-07-15 15:44:40 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2010-07-15 15:44:40 +0000
commitbbe6a5fe81a4531b24c10e6b861c7cebe787d24b (patch)
tree733ecfd7176cb539040eade43dcd8a86d04c5a30 /cpukit/score/src/coremutexsurrender.c
parent2010-07-15 Bharath Suri <bharath.s.jois@gmail.com> (diff)
downloadrtems-bbe6a5fe81a4531b24c10e6b861c7cebe787d24b.tar.bz2
2010-07-15 Sebastian Huber <Sebastian.Huber@embedded-brains.de>
PR 1607/cpukit * score/src/coremutexsurrender.c: Clean up and split out helper routines.
Diffstat (limited to '')
-rw-r--r--cpukit/score/src/coremutexsurrender.c99
1 files changed, 63 insertions, 36 deletions
diff --git a/cpukit/score/src/coremutexsurrender.c b/cpukit/score/src/coremutexsurrender.c
index 4d215bb2d1..cfe40ab77d 100644
--- a/cpukit/score/src/coremutexsurrender.c
+++ b/cpukit/score/src/coremutexsurrender.c
@@ -27,6 +27,51 @@
#include <rtems/score/thread.h>
#include <rtems/score/threadq.h>
+#ifdef __RTEMS_STRICT_ORDER_MUTEX__
+ static inline void _CORE_mutex_Push_priority(
+ CORE_mutex_Control *mutex,
+ Thread_Control *thread
+ )
+ {
+ _Chain_Prepend_unprotected(
+ &thread->lock_mutex,
+ &mutex->queue.lock_queue
+ );
+ mutex->queue.priority_before = thread->current_priority;
+ }
+
+ static inline CORE_mutex_Status _CORE_mutex_Pop_priority(
+ CORE_mutex_Control *mutex,
+ Thread_Control *holder
+ )
+ {
+ /*
+ * Check whether the holder release the mutex in LIFO order if not return
+ * error code.
+ */
+ if ( _Chain_First( holder->lock_mutex ) != &mutex->queue.lock_queue ) {
+ mutex->nest_count++;
+
+ return CORE_MUTEX_RELEASE_NOT_ORDER;
+ }
+
+ /*
+ * This pops the first node from the list.
+ */
+ _Chain_Get_first_unprotected( &holder->lock_mutex );
+
+ if ( mutex->queue.priority_before != holder->current_priority )
+ _Thread_Change_priority( holder, mutex->queue.priority_before, true );
+
+ return CORE_MUTEX_STATUS_SUCCESSFUL;
+ }
+#else
+ #define _CORE_mutex_Push_priority( mutex, thread ) ((void) 0)
+
+ #define _CORE_mutex_Pop_priority( mutex, thread ) \
+ CORE_MUTEX_STATUS_SUCCESSFUL
+#endif
+
/*
* _CORE_mutex_Surrender
*
@@ -59,10 +104,8 @@ CORE_mutex_Status _CORE_mutex_Surrender(
{
Thread_Control *the_thread;
Thread_Control *holder;
-#ifdef __RTEMS_STRICT_ORDER_MUTEX__
- Chain_Node *first_node;
-#endif
- holder = the_mutex->holder;
+
+ holder = the_mutex->holder;
/*
* The following code allows a thread (or ISR) other than the thread
@@ -112,37 +155,27 @@ CORE_mutex_Status _CORE_mutex_Surrender(
* blocked thread.
*/
if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
- _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ){
-#ifdef __RTEMS_STRICT_ORDER_MUTEX__
- /*Check whether the holder release the mutex in LIFO order
- if not return error code*/
- if(holder->lock_mutex.first != &the_mutex->queue.lock_queue){
- the_mutex->nest_count++;
- return CORE_MUTEX_RELEASE_NOT_ORDER;
- }
- first_node = _Chain_Get_first_unprotected(&holder->lock_mutex);
-#endif
+ _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
+ CORE_mutex_Status pop_status =
+ _CORE_mutex_Pop_priority( the_mutex, holder );
+
+ if ( pop_status != CORE_MUTEX_STATUS_SUCCESSFUL )
+ return pop_status;
+
holder->resource_count--;
- }
- the_mutex->holder = NULL;
- the_mutex->holder_id = 0;
- /*
- * Whether or not someone is waiting for the mutex, an
- * inherited priority must be lowered if this is the last
- * mutex (i.e. resource) this task has.
- */
- if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
- _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
-#ifdef __RTEMS_STRICT_ORDER_MUTEX__
- if(the_mutex->queue.priority_before != holder->current_priority)
- _Thread_Change_priority(holder,the_mutex->queue.priority_before,true);
-#endif
+ /*
+ * Whether or not someone is waiting for the mutex, an
+ * inherited priority must be lowered if this is the last
+ * mutex (i.e. resource) this task has.
+ */
if ( holder->resource_count == 0 &&
holder->real_priority != holder->current_priority ) {
_Thread_Change_priority( holder, holder->real_priority, true );
}
}
+ the_mutex->holder = NULL;
+ the_mutex->holder_id = 0;
/*
* Now we check if another thread was waiting for this mutex. If so,
@@ -172,17 +205,11 @@ CORE_mutex_Status _CORE_mutex_Surrender(
case CORE_MUTEX_DISCIPLINES_PRIORITY:
break;
case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
-#ifdef __RTEMS_STRICT_ORDER_MUTEX__
- _Chain_Prepend_unprotected(&the_thread->lock_mutex,&the_mutex->queue.lock_queue);
- the_mutex->queue.priority_before = the_thread->current_priority;
-#endif
+ _CORE_mutex_Push_priority( the_mutex, the_thread );
the_thread->resource_count++;
break;
case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
-#ifdef __RTEMS_STRICT_ORDER_MUTEX__
- _Chain_Prepend_unprotected(&the_thread->lock_mutex,&the_mutex->queue.lock_queue);
- the_mutex->queue.priority_before = the_thread->current_priority;
-#endif
+ _CORE_mutex_Push_priority( the_mutex, the_thread );
the_thread->resource_count++;
if (the_mutex->Attributes.priority_ceiling <
the_thread->current_priority){