summaryrefslogtreecommitdiffstats
path: root/cpukit/rtems/src/semcreate.c
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2019-12-07 11:48:36 +0100
committerSebastian Huber <sebastian.huber@embedded-brains.de>2019-12-11 09:05:07 +0100
commit01f8c12ee57230fca1581e1b5be91f3decba0488 (patch)
tree279ef8193d107ea59490e3fdeb18d20639c54f36 /cpukit/rtems/src/semcreate.c
parentscore: Optimize _TLS_Get_size() (diff)
downloadrtems-01f8c12ee57230fca1581e1b5be91f3decba0488.tar.bz2
rtems: Optimize semaphore control block
Move variant, discipline, and global information to flags stored in a node pointer of active semaphores. Update #3833.
Diffstat (limited to 'cpukit/rtems/src/semcreate.c')
-rw-r--r--cpukit/rtems/src/semcreate.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/cpukit/rtems/src/semcreate.c b/cpukit/rtems/src/semcreate.c
index dc4e02cd97..81a968107f 100644
--- a/cpukit/rtems/src/semcreate.c
+++ b/cpukit/rtems/src/semcreate.c
@@ -47,6 +47,7 @@ rtems_status_code rtems_semaphore_create(
const Scheduler_Control *scheduler;
bool valid;
Priority_Control priority;
+ uintptr_t flags;
if ( !rtems_is_name_valid( name ) )
return RTEMS_INVALID_NAME;
@@ -116,29 +117,39 @@ rtems_status_code rtems_semaphore_create(
return RTEMS_TOO_MANY;
}
+ flags = _Semaphore_Set_variant( 0, variant );
+
#if defined(RTEMS_MULTIPROCESSING)
- the_semaphore->is_global = _Attributes_Is_global( attribute_set );
+ if ( _Attributes_Is_global( attribute_set ) ) {
+ bool ok;
- if ( _Attributes_Is_global( attribute_set ) &&
- ! ( _Objects_MP_Allocate_and_open( &_Semaphore_Information, name,
- the_semaphore->Object.id, false ) ) ) {
- _Semaphore_Free( the_semaphore );
- _Objects_Allocator_unlock();
- return RTEMS_TOO_MANY;
- }
-#endif
+ ok = _Objects_MP_Allocate_and_open(
+ &_Semaphore_Information,
+ name,
+ the_semaphore->Object.id,
+ false
+ );
- executing = _Thread_Get_executing();
+ if ( !ok ) {
+ _Semaphore_Free( the_semaphore );
+ _Objects_Allocator_unlock();
+ return RTEMS_TOO_MANY;
+ }
- the_semaphore->variant = variant;
+ flags = _Semaphore_Make_global( flags );
+ }
+#endif
if ( _Attributes_Is_priority( attribute_set ) ) {
- the_semaphore->discipline = SEMAPHORE_DISCIPLINE_PRIORITY;
+ flags = _Semaphore_Set_discipline( flags, SEMAPHORE_DISCIPLINE_PRIORITY );
} else {
- the_semaphore->discipline = SEMAPHORE_DISCIPLINE_FIFO;
+ flags = _Semaphore_Set_discipline( flags, SEMAPHORE_DISCIPLINE_FIFO );
}
- switch ( the_semaphore->variant ) {
+ _Semaphore_Set_flags( the_semaphore, flags );
+ executing = _Thread_Get_executing();
+
+ switch ( variant ) {
case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
_CORE_recursive_mutex_Initialize(
@@ -214,8 +225,8 @@ rtems_status_code rtems_semaphore_create(
#endif
default:
_Assert(
- the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
- || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING
+ variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
+ || variant == SEMAPHORE_VARIANT_COUNTING
);
_CORE_semaphore_Initialize(
&the_semaphore->Core_control.Semaphore,