void rtems_monitor_sema_canonical( rtems_monitor_sema_t *canonical_sema, const void *sema_void ) { const Semaphore_Control *rtems_sema = (const Semaphore_Control *) sema_void; Thread_Control *owner; memset(canonical_sema, 0, sizeof(*canonical_sema)); #if defined(RTEMS_MULTIPROCESSING) if (rtems_sema->is_global) { canonical_sema->attribute |= RTEMS_GLOBAL; } #endif 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; } switch ( rtems_sema->variant ) { case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING: canonical_sema->priority_ceiling = _Scheduler_Unmap_priority( _CORE_ceiling_mutex_Get_scheduler( &rtems_sema->Core_control.Mutex ), _CORE_ceiling_mutex_Get_priority( &rtems_sema->Core_control.Mutex ) ); /* 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 = _MRSP_Get_owner( &rtems_sema->Core_control.MRSP ) == 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; } }
static rtems_status_code _Semaphore_Set_priority( Semaphore_Control *the_semaphore, const Scheduler_Control *scheduler, rtems_task_priority new_priority, rtems_task_priority *old_priority_p, Thread_queue_Context *queue_context ) { rtems_status_code sc; bool valid; Priority_Control core_priority; Priority_Control old_priority; core_priority = _RTEMS_Priority_To_core( scheduler, new_priority, &valid ); if ( new_priority != RTEMS_CURRENT_PRIORITY && !valid ) { return RTEMS_INVALID_PRIORITY; } _Thread_queue_Acquire_critical( &the_semaphore->Core_control.Wait_queue, &queue_context->Lock_context ); switch ( the_semaphore->variant ) { case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING: sc = _Semaphore_Is_scheduler_valid( &the_semaphore->Core_control.Mutex, scheduler ); old_priority = _CORE_ceiling_mutex_Get_priority( &the_semaphore->Core_control.Mutex ); if ( sc == RTEMS_SUCCESSFUL && new_priority != RTEMS_CURRENT_PRIORITY ) { _CORE_ceiling_mutex_Set_priority( &the_semaphore->Core_control.Mutex, core_priority ); } break; #if defined(RTEMS_SMP) case SEMAPHORE_VARIANT_MRSP: old_priority = _MRSP_Get_priority( &the_semaphore->Core_control.MRSP, scheduler ); if ( new_priority != RTEMS_CURRENT_PRIORITY ) { _MRSP_Set_priority( &the_semaphore->Core_control.MRSP, scheduler, core_priority ); } sc = RTEMS_SUCCESSFUL; break; #endif default: _Assert( the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY || the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL || the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING ); old_priority = 0; sc = RTEMS_NOT_DEFINED; break; } _Thread_queue_Release( &the_semaphore->Core_control.Wait_queue, &queue_context->Lock_context ); *old_priority_p = _RTEMS_Priority_From_core( scheduler, old_priority ); return sc; }