int _POSIX_Mutex_Lock_support( pthread_mutex_t *mutex, bool blocking, Watchdog_Interval timeout ) { register POSIX_Mutex_Control *the_mutex; Objects_Locations location; ISR_Level level; the_mutex = _POSIX_Mutex_Get_interrupt_disable( mutex, &location, &level ); switch ( location ) { case OBJECTS_LOCAL: _CORE_mutex_Seize( &the_mutex->Mutex, the_mutex->Object.id, blocking, timeout, level ); return _POSIX_Mutex_Translate_core_mutex_return_code( (CORE_mutex_Status) _Thread_Executing->Wait.return_code ); #if defined(RTEMS_MULTIPROCESSING) case OBJECTS_REMOTE: #endif case OBJECTS_ERROR: break; } return EINVAL; }
void _API_Mutex_Lock( API_Mutex_Control *the_mutex ) { bool previous_thread_life_protection; ISR_Level level; previous_thread_life_protection = _Thread_Set_life_protection( true ); #if defined(RTEMS_SMP) _Thread_Disable_dispatch(); #endif _ISR_Disable( level ); _CORE_mutex_Seize( &the_mutex->Mutex, _Thread_Executing, the_mutex->Object.id, true, 0, level ); if ( the_mutex->Mutex.nest_count == 1 ) { the_mutex->previous_thread_life_protection = previous_thread_life_protection; } #if defined(RTEMS_SMP) _Thread_Enable_dispatch(); #endif }
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 */ }
void _API_Mutex_Lock( API_Mutex_Control *the_mutex ) { ISR_Level level; _ISR_Disable( level ); _CORE_mutex_Seize( &the_mutex->Mutex, the_mutex->Object.id, true, 0, level ); }
void _API_Mutex_Lock( API_Mutex_Control *the_mutex ) { ISR_Level level; #if defined(RTEMS_SMP) _Thread_Disable_dispatch(); #endif _ISR_Disable( level ); _CORE_mutex_Seize( &the_mutex->Mutex, the_mutex->Object.id, true, 0, level ); }
void _API_Mutex_Lock( API_Mutex_Control *the_mutex ) { bool previous_thread_life_protection; ISR_lock_Context lock_context; previous_thread_life_protection = _Thread_Set_life_protection( true ); _ISR_lock_ISR_disable( &lock_context ); _CORE_mutex_Seize( &the_mutex->Mutex, _Thread_Executing, the_mutex->Object.id, true, 0, &lock_context ); if ( the_mutex->Mutex.nest_count == 1 ) { the_mutex->previous_thread_life_protection = previous_thread_life_protection; } }
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; }