From 7d91d722baf1f1ff275fd31500526bb2fd6df632 Mon Sep 17 00:00:00 2001 From: Joel Sherrill Date: Mon, 13 Dec 1999 15:29:20 +0000 Subject: First attempt at adding simple binary semaphore in addition to the current "mutex" and counting semaphore. This is at the request of Eric Norum and his EPICS porting effort. --- c/src/exec/score/src/coremutexseize.c | 1 + c/src/exec/score/src/coremutexsurrender.c | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 12 deletions(-) (limited to 'c/src/exec/score/src') diff --git a/c/src/exec/score/src/coremutexseize.c b/c/src/exec/score/src/coremutexseize.c index 0fe5fd288a..c2a70da762 100644 --- a/c/src/exec/score/src/coremutexseize.c +++ b/c/src/exec/score/src/coremutexseize.c @@ -90,6 +90,7 @@ void _CORE_mutex_Seize( ); } } + executing->Wait.return_code = CORE_MUTEX_STATUS_SUCCESSFUL; return; } diff --git a/c/src/exec/score/src/coremutexsurrender.c b/c/src/exec/score/src/coremutexsurrender.c index fbd75fd8e8..7f5fc2e911 100644 --- a/c/src/exec/score/src/coremutexsurrender.c +++ b/c/src/exec/score/src/coremutexsurrender.c @@ -61,24 +61,31 @@ CORE_mutex_Status _CORE_mutex_Surrender( * must be released by the thread which acquired them. */ - if ( !_Objects_Are_ids_equal( - _Thread_Executing->Object.id, the_mutex->holder_id ) ) { - - switch ( the_mutex->Attributes.discipline ) { - case CORE_MUTEX_DISCIPLINES_FIFO: - case CORE_MUTEX_DISCIPLINES_PRIORITY: - break; - case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING: - case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT: - return( CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE ); - break; + if ( the_mutex->Attributes.allow_nesting ) { + if ( !_Objects_Are_ids_equal( + _Thread_Executing->Object.id, the_mutex->holder_id ) ) { + + switch ( the_mutex->Attributes.discipline ) { + case CORE_MUTEX_DISCIPLINES_FIFO: + case CORE_MUTEX_DISCIPLINES_PRIORITY: + break; + case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING: + case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT: + return( CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE ); + break; + } } } + /* XXX already unlocked -- not right status */ + + if ( !the_mutex->nest_count ) + return( CORE_MUTEX_STATUS_SUCCESSFUL ); + the_mutex->nest_count--; if ( the_mutex->nest_count != 0 ) - return( CORE_MUTEX_STATUS_SUCCESSFUL ); + return( CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED ); _Thread_Executing->resource_count--; the_mutex->holder = NULL; -- cgit v1.2.3