rtems_status_code rtems_semaphore_obtain( rtems_id id, rtems_option option_set, rtems_interval timeout ) { register Semaphore_Control *the_semaphore; Objects_Locations location; ISR_Level level; Thread_Control *executing; the_semaphore = _Semaphore_Get_interrupt_disable( id, &location, &level ); switch ( location ) { case OBJECTS_LOCAL: executing = _Thread_Executing; if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) { _CORE_mutex_Seize( &the_semaphore->Core_control.mutex, executing, id, ((_Options_Is_no_wait( option_set )) ? false : true), timeout, level ); _Objects_Put_for_get_isr_disable( &the_semaphore->Object ); return _Semaphore_Translate_core_mutex_return_code( executing->Wait.return_code ); } /* must be a counting semaphore */ _CORE_semaphore_Seize_isr_disable( &the_semaphore->Core_control.semaphore, executing, id, ((_Options_Is_no_wait( option_set )) ? false : true), timeout, level ); _Objects_Put_for_get_isr_disable( &the_semaphore->Object ); return _Semaphore_Translate_core_semaphore_return_code( executing->Wait.return_code ); #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: return _Semaphore_MP_Send_request_packet( SEMAPHORE_MP_OBTAIN_REQUEST, id, option_set, timeout ); #endif case OBJECTS_ERROR: break; } return RTEMS_INVALID_ID; }
rtems_status_code rtems_semaphore_obtain( Objects_Id id, unsigned32 option_set, rtems_interval timeout ) { register Semaphore_Control *the_semaphore; Objects_Locations location; boolean wait; the_semaphore = _Semaphore_Get( id, &location ); switch ( location ) { case OBJECTS_REMOTE: #if defined(RTEMS_MULTIPROCESSING) return _Semaphore_MP_Send_request_packet( SEMAPHORE_MP_OBTAIN_REQUEST, id, option_set, timeout ); #endif case OBJECTS_ERROR: return RTEMS_INVALID_ID; case OBJECTS_LOCAL: if ( _Options_Is_no_wait( option_set ) ) wait = FALSE; else wait = TRUE; if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) { _CORE_mutex_Seize( &the_semaphore->Core_control.mutex, id, wait, timeout ); _Thread_Enable_dispatch(); return _Semaphore_Translate_core_mutex_return_code( _Thread_Executing->Wait.return_code ); } else { _CORE_semaphore_Seize( &the_semaphore->Core_control.semaphore, id, wait, timeout ); _Thread_Enable_dispatch(); return _Semaphore_Translate_core_semaphore_return_code( _Thread_Executing->Wait.return_code ); } } return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ }
rtems_status_code rtems_semaphore_obtain( rtems_id id, uint32_t option_set, rtems_interval timeout ) { register Semaphore_Control *the_semaphore; Objects_Locations location; ISR_Level level; the_semaphore = _Semaphore_Get_interrupt_disable( id, &location, &level ); switch ( location ) { case OBJECTS_REMOTE: #if defined(RTEMS_MULTIPROCESSING) return _Semaphore_MP_Send_request_packet( SEMAPHORE_MP_OBTAIN_REQUEST, id, option_set, timeout ); #endif case OBJECTS_ERROR: return RTEMS_INVALID_ID; case OBJECTS_LOCAL: if ( !_Attributes_Is_counting_semaphore(the_semaphore->attribute_set) ) { _CORE_mutex_Seize( &the_semaphore->Core_control.mutex, id, ((_Options_Is_no_wait( option_set )) ? FALSE : TRUE), timeout, level ); return _Semaphore_Translate_core_mutex_return_code( _Thread_Executing->Wait.return_code ); } /* must be a counting semaphore */ _CORE_semaphore_Seize_isr_disable( &the_semaphore->Core_control.semaphore, id, ((_Options_Is_no_wait( option_set )) ? FALSE : TRUE), timeout, &level ); return _Semaphore_Translate_core_semaphore_return_code( _Thread_Executing->Wait.return_code ); } return RTEMS_INTERNAL_ERROR; /* unreached - only to remove warnings */ }
rtems_status_code rtems_semaphore_obtain( rtems_id id, rtems_option option_set, rtems_interval timeout ) { Semaphore_Control *the_semaphore; Objects_Locations location; ISR_Level level; Thread_Control *executing; rtems_attribute attribute_set; bool wait; the_semaphore = _Semaphore_Get_interrupt_disable( id, &location, &level ); switch ( location ) { case OBJECTS_LOCAL: executing = _Thread_Executing; attribute_set = the_semaphore->attribute_set; wait = !_Options_Is_no_wait( option_set ); #if defined(RTEMS_SMP) if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) { MRSP_Status mrsp_status; _ISR_Enable( level ); mrsp_status = _MRSP_Obtain( &the_semaphore->Core_control.mrsp, executing, wait, timeout ); _Objects_Put_for_get_isr_disable( &the_semaphore->Object ); return _Semaphore_Translate_MRSP_status_code( mrsp_status ); } else #endif if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) { _CORE_mutex_Seize( &the_semaphore->Core_control.mutex, executing, id, wait, timeout, level ); _Objects_Put_for_get_isr_disable( &the_semaphore->Object ); return _Semaphore_Translate_core_mutex_return_code( executing->Wait.return_code ); } /* must be a counting semaphore */ _CORE_semaphore_Seize_isr_disable( &the_semaphore->Core_control.semaphore, executing, id, wait, timeout, level ); _Objects_Put_for_get_isr_disable( &the_semaphore->Object ); return _Semaphore_Translate_core_semaphore_return_code( executing->Wait.return_code ); #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: return _Semaphore_MP_Send_request_packet( SEMAPHORE_MP_OBTAIN_REQUEST, id, option_set, timeout ); #endif case OBJECTS_ERROR: break; } return RTEMS_INVALID_ID; }
rtems_status_code rtems_semaphore_release( rtems_id id ) { Semaphore_Control *the_semaphore; Objects_Locations location; CORE_mutex_Status mutex_status; CORE_semaphore_Status semaphore_status; rtems_attribute attribute_set; ISR_lock_Context lock_context; the_semaphore = _Semaphore_Get_interrupt_disable( id, &location, &lock_context ); switch ( location ) { case OBJECTS_LOCAL: attribute_set = the_semaphore->attribute_set; #if defined(RTEMS_SMP) if ( _Attributes_Is_multiprocessor_resource_sharing( attribute_set ) ) { MRSP_Status mrsp_status; mrsp_status = _MRSP_Surrender( &the_semaphore->Core_control.mrsp, _Thread_Executing, &lock_context ); return _Semaphore_Translate_MRSP_status_code( mrsp_status ); } else #endif if ( !_Attributes_Is_counting_semaphore( attribute_set ) ) { mutex_status = _CORE_mutex_Surrender( &the_semaphore->Core_control.mutex, _Semaphore_Core_mutex_mp_support, id, &lock_context ); return _Semaphore_Translate_core_mutex_return_code( mutex_status ); } else { semaphore_status = _CORE_semaphore_Surrender( &the_semaphore->Core_control.semaphore, _Semaphore_Core_mutex_mp_support, id, &lock_context ); return _Semaphore_Translate_core_semaphore_return_code( semaphore_status ); } #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: return _Semaphore_MP_Send_request_packet( SEMAPHORE_MP_RELEASE_REQUEST, id, 0, /* Not used */ MPCI_DEFAULT_TIMEOUT ); #endif case OBJECTS_ERROR: break; } return RTEMS_INVALID_ID; }