void _Mutex_recursive_Acquire( struct _Mutex_recursive_Control *_mutex ) { Mutex_recursive_Control *mutex; Thread_queue_Context queue_context; ISR_Level level; Thread_Control *executing; Thread_Control *owner; mutex = _Mutex_recursive_Get( _mutex ); _Thread_queue_Context_initialize( &queue_context ); _Thread_queue_Context_ISR_disable( &queue_context, level ); executing = _Mutex_Queue_acquire_critical( &mutex->Mutex, &queue_context ); owner = mutex->Mutex.Queue.Queue.owner; if ( __predict_true( owner == NULL ) ) { mutex->Mutex.Queue.Queue.owner = executing; _Thread_Resource_count_increment( executing ); _Mutex_Queue_release( &mutex->Mutex, level, &queue_context ); } else if ( owner == executing ) { ++mutex->nest_level; _Mutex_Queue_release( &mutex->Mutex, level, &queue_context ); } else { _Thread_queue_Context_set_no_timeout( &queue_context ); _Mutex_Acquire_slow( &mutex->Mutex, owner, executing, level, &queue_context ); } }
void _Mutex_recursive_Acquire( struct _Mutex_recursive_Control *_mutex ) { Mutex_recursive_Control *mutex; Thread_queue_Context queue_context; Thread_Control *executing; Thread_Control *owner; mutex = _Mutex_recursive_Get( _mutex ); _Thread_queue_Context_initialize( &queue_context ); executing = _Mutex_Queue_acquire( &mutex->Mutex, &queue_context ); owner = mutex->Mutex.Queue.Queue.owner; if ( __predict_true( owner == NULL ) ) { mutex->Mutex.Queue.Queue.owner = executing; ++executing->resource_count; _Mutex_Queue_release( &mutex->Mutex, &queue_context ); } else if ( owner == executing ) { ++mutex->nest_level; _Mutex_Queue_release( &mutex->Mutex, &queue_context ); } else { _Thread_queue_Context_set_no_timeout( &queue_context ); _Mutex_Acquire_slow( &mutex->Mutex, owner, executing, &queue_context ); } }
int _Mutex_recursive_Acquire_timed( struct _Mutex_recursive_Control *_mutex, const struct timespec *abstime ) { Mutex_recursive_Control *mutex; ISR_lock_Context lock_context; Thread_Control *executing; Thread_Control *owner; mutex = _Mutex_recursive_Get( _mutex ); executing = _Mutex_Queue_acquire( &mutex->Mutex, &lock_context ); owner = mutex->Mutex.owner; if ( __predict_true( owner == NULL ) ) { mutex->Mutex.owner = executing; ++executing->resource_count; _Mutex_Queue_release( &mutex->Mutex, &lock_context ); return 0; } else if ( owner == executing ) { ++mutex->nest_level; _Mutex_Queue_release( &mutex->Mutex, &lock_context ); return 0; } else { Watchdog_Interval ticks; switch ( _TOD_Absolute_timeout_to_ticks( abstime, &ticks ) ) { case TOD_ABSOLUTE_TIMEOUT_INVALID: _Mutex_Queue_release( &mutex->Mutex, &lock_context ); return EINVAL; case TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST: case TOD_ABSOLUTE_TIMEOUT_IS_NOW: _Mutex_Queue_release( &mutex->Mutex, &lock_context ); return ETIMEDOUT; default: break; } executing->Wait.return_code = 0; _Mutex_Acquire_slow( &mutex->Mutex, owner, executing, ticks, &lock_context ); return (int) executing->Wait.return_code; } }
int _Mutex_recursive_Acquire_timed( struct _Mutex_recursive_Control *_mutex, const struct timespec *abstime ) { Mutex_recursive_Control *mutex; Thread_queue_Context queue_context; ISR_Level level; Thread_Control *executing; Thread_Control *owner; mutex = _Mutex_recursive_Get( _mutex ); _Thread_queue_Context_initialize( &queue_context ); _Thread_queue_Context_ISR_disable( &queue_context, level ); executing = _Mutex_Queue_acquire_critical( &mutex->Mutex, &queue_context ); owner = mutex->Mutex.Queue.Queue.owner; if ( __predict_true( owner == NULL ) ) { mutex->Mutex.Queue.Queue.owner = executing; _Thread_Resource_count_increment( executing ); _Mutex_Queue_release( &mutex->Mutex, level, &queue_context ); return 0; } else if ( owner == executing ) { ++mutex->nest_level; _Mutex_Queue_release( &mutex->Mutex, level, &queue_context ); return 0; } else { Watchdog_Interval ticks; switch ( _TOD_Absolute_timeout_to_ticks( abstime, CLOCK_REALTIME, &ticks ) ) { case TOD_ABSOLUTE_TIMEOUT_INVALID: _Mutex_Queue_release( &mutex->Mutex, level, &queue_context ); return EINVAL; case TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST: case TOD_ABSOLUTE_TIMEOUT_IS_NOW: _Mutex_Queue_release( &mutex->Mutex, level, &queue_context ); return ETIMEDOUT; default: break; } _Thread_queue_Context_set_relative_timeout( &queue_context, ticks ); _Mutex_Acquire_slow( &mutex->Mutex, owner, executing, level, &queue_context ); return STATUS_GET_POSIX( _Thread_Wait_get_status( executing ) ); } }
void _Mutex_Acquire( struct _Mutex_Control *_mutex ) { Mutex_Control *mutex; ISR_lock_Context lock_context; Thread_Control *executing; Thread_Control *owner; mutex = _Mutex_Get( _mutex ); executing = _Mutex_Queue_acquire( mutex, &lock_context ); owner = mutex->owner; ++executing->resource_count; if ( __predict_true( owner == NULL ) ) { mutex->owner = executing; _Mutex_Queue_release( mutex, &lock_context ); } else { _Mutex_Acquire_slow( mutex, owner, executing, 0, &lock_context ); } }
void _Mutex_recursive_Acquire( struct _Mutex_recursive_Control *_mutex ) { Mutex_recursive_Control *mutex; ISR_lock_Context lock_context; Thread_Control *executing; Thread_Control *owner; mutex = _Mutex_recursive_Get( _mutex ); executing = _Mutex_Queue_acquire( &mutex->Mutex, &lock_context ); owner = mutex->Mutex.owner; if ( __predict_true( owner == NULL ) ) { mutex->Mutex.owner = executing; ++executing->resource_count; _Mutex_Queue_release( &mutex->Mutex, &lock_context ); } else if ( owner == executing ) { ++mutex->nest_level; _Mutex_Queue_release( &mutex->Mutex, &lock_context ); } else { _Mutex_Acquire_slow( &mutex->Mutex, owner, executing, 0, &lock_context ); } }