summaryrefslogtreecommitdiffstats
path: root/cpukit/score/src/coremutexsurrender.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2007-12-21 15:50:09 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2007-12-21 15:50:09 +0000
commitfd84982c0019205ea5e4c226f47dd62480cfd5e6 (patch)
treeb2915444f038f690cd390dfee72cc896319ba7b4 /cpukit/score/src/coremutexsurrender.c
parentcd2255151a80a4967c1a60dd54bb0b63a47177d4 (diff)
downloadrtems-fd84982c0019205ea5e4c226f47dd62480cfd5e6.tar.bz2
2007-12-21 Xi Yang <hiyangxi@gmail.com>
* configure.ac, score/include/rtems/score/coremutex.h, score/include/rtems/score/thread.h, score/inline/rtems/score/coremutex.inl, score/src/coremutexsurrender.c, score/src/threadinitialize.c: Add support for proper stacking of priority inheritance on mutexes as well as enforce proper order of release.
Diffstat (limited to 'cpukit/score/src/coremutexsurrender.c')
-rw-r--r--cpukit/score/src/coremutexsurrender.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/cpukit/score/src/coremutexsurrender.c b/cpukit/score/src/coremutexsurrender.c
index 839c0af5bf..29b246983f 100644
--- a/cpukit/score/src/coremutexsurrender.c
+++ b/cpukit/score/src/coremutexsurrender.c
@@ -54,7 +54,9 @@ CORE_mutex_Status _CORE_mutex_Surrender(
{
Thread_Control *the_thread;
Thread_Control *holder;
-
+#ifdef __STRICT_ORDER_MUTEX__
+ Chain_Node *first_node;
+#endif
holder = the_mutex->holder;
/*
@@ -95,8 +97,18 @@ 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 ) )
+ _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ){
+#ifdef __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
holder->resource_count--;
+ }
the_mutex->holder = NULL;
the_mutex->holder_id = 0;
@@ -107,6 +119,10 @@ CORE_mutex_Status _CORE_mutex_Surrender(
*/
if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
+#ifdef __STRICT_ORDER_MUTEX__
+ if(the_mutex->queue.priority_before != holder->current_priority)
+ _Thread_Change_priority(holder,the_mutex->queue.priority_before,TRUE);
+#endif
if ( holder->resource_count == 0 &&
holder->real_priority != holder->current_priority ) {
_Thread_Change_priority( holder, holder->real_priority, TRUE );
@@ -141,9 +157,17 @@ CORE_mutex_Status _CORE_mutex_Surrender(
case CORE_MUTEX_DISCIPLINES_PRIORITY:
break;
case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
+#ifdef __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
the_thread->resource_count++;
break;
case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
+#ifdef __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
the_thread->resource_count++;
if (the_mutex->Attributes.priority_ceiling <
the_thread->current_priority){