diff options
author | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-30 06:59:55 +0200 |
---|---|---|
committer | Sebastian Huber <sebastian.huber@embedded-brains.de> | 2016-05-30 16:16:23 +0200 |
commit | 0b713f8940d90b480f8cd36663c11aa0688587d8 (patch) | |
tree | c71a01748c3749e0243518b486c2bb32a1c67df1 /cpukit/libmisc/monitor/mon-sema.c | |
parent | 33e250c9fa370f620ddbc5850342d5a90b123524 (diff) |
score: Rework CORE inherit priority mutex
Provide dedicated seize and surrender methods for inherit priority
mutexes. This eliminates CORE_mutex_Attributes.
Diffstat (limited to 'cpukit/libmisc/monitor/mon-sema.c')
-rw-r--r-- | cpukit/libmisc/monitor/mon-sema.c | 94 |
1 files changed, 72 insertions, 22 deletions
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 <rtems.h> #include "monitor.h" -#include <rtems/rtems/attrimpl.h> +#include <rtems/rtems/semimpl.h> #include <stdio.h> #include <string.h> /* 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; } } |