From 0b713f8940d90b480f8cd36663c11aa0688587d8 Mon Sep 17 00:00:00 2001 From: Sebastian Huber Date: Mon, 30 May 2016 06:59:55 +0200 Subject: score: Rework CORE inherit priority mutex Provide dedicated seize and surrender methods for inherit priority mutexes. This eliminates CORE_mutex_Attributes. --- cpukit/libmisc/monitor/mon-sema.c | 94 ++++++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 22 deletions(-) (limited to 'cpukit/libmisc/monitor') diff --git a/cpukit/libmisc/monitor/mon-sema.c b/cpukit/libmisc/monitor/mon-sema.c index bc745294e7..d7a7aafc9c 100644 --- a/cpukit/libmisc/monitor/mon-sema.c +++ b/cpukit/libmisc/monitor/mon-sema.c @@ -8,7 +8,7 @@ #include #include "monitor.h" -#include +#include #include #include /* memcpy() */ @@ -19,31 +19,81 @@ rtems_monitor_sema_canonical( ) { const Semaphore_Control *rtems_sema = (const Semaphore_Control *) sema_void; + Thread_Control *owner; - canonical_sema->attribute = rtems_sema->attribute_set; - canonical_sema->priority_ceiling = - rtems_sema->Core_control.Mutex.priority_ceiling; + memset(canonical_sema, 0, sizeof(*canonical_sema)); - canonical_sema->holder_id = 0; +#if defined(RTEMS_MULTIPROCESSING) + if (rtems_sema->is_global) { + canonical_sema->attribute |= RTEMS_GLOBAL; + } +#endif - if (_Attributes_Is_counting_semaphore(canonical_sema->attribute)) { - /* we have a counting semaphore */ - canonical_sema->cur_count = rtems_sema->Core_control.semaphore.count; - canonical_sema->max_count = UINT32_MAX; + if (rtems_sema->discipline == SEMAPHORE_DISCIPLINE_PRIORITY) { + canonical_sema->attribute |= RTEMS_PRIORITY; + } + + switch ( rtems_sema->variant ) { + case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY: + canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE + | RTEMS_INHERIT_PRIORITY; + break; + case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING: + canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE + | RTEMS_PRIORITY_CEILING; + break; + case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL: + canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE; + break; +#if defined(RTEMS_SMP) + case SEMAPHORE_VARIANT_MRSP: + canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE + | RTEMS_MULTIPROCESSOR_RESOURCE_SHARING; + break; +#endif + case SEMAPHORE_VARIANT_SIMPLE_BINARY: + canonical_sema->attribute |= RTEMS_SIMPLE_BINARY_SEMAPHORE; + break; + case SEMAPHORE_VARIANT_COUNTING: + canonical_sema->attribute |= RTEMS_COUNTING_SEMAPHORE; + break; } - else { - /* we have a binary semaphore (mutex) */ - Thread_Control *holder; - - holder = rtems_sema->Core_control.Mutex.Recursive.Mutex.holder; - if (holder != NULL) { - canonical_sema->holder_id = holder->Object.id; - canonical_sema->cur_count = 0; - } else { - canonical_sema->cur_count = 1; - } - - canonical_sema->max_count = 1; /* mutex is either 0 or 1 */ + + switch ( rtems_sema->variant ) { + case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING: + canonical_sema->priority_ceiling = + rtems_sema->Core_control.Mutex.priority_ceiling; + /* Fall through */ + case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY: + case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL: + owner = _CORE_mutex_Get_owner( + &rtems_sema->Core_control.Mutex.Recursive.Mutex + ); + + if (owner != NULL) { + canonical_sema->holder_id = owner->Object.id; + canonical_sema->cur_count = 0; + } else { + canonical_sema->cur_count = 1; + } + + canonical_sema->max_count = 1; + break; +#if defined(RTEMS_SMP) + case SEMAPHORE_VARIANT_MRSP: + canonical_sema->cur_count = + rtems_sema->Core_control.mrsp.Resource.owner == NULL; + canonical_sema->max_count = 1; + break; +#endif + case SEMAPHORE_VARIANT_SIMPLE_BINARY: + canonical_sema->cur_count = rtems_sema->Core_control.semaphore.count; + canonical_sema->max_count = 1; + break; + case SEMAPHORE_VARIANT_COUNTING: + canonical_sema->cur_count = rtems_sema->Core_control.semaphore.count; + canonical_sema->max_count = UINT32_MAX; + break; } } -- cgit v1.2.3