static void _Mutex_Acquire_slow( Mutex_Control *mutex, Thread_Control *owner, Thread_Control *executing, ISR_Level level, Thread_queue_Context *queue_context ) { _Thread_queue_Context_set_thread_state( queue_context, STATES_WAITING_FOR_SYS_LOCK_MUTEX ); _Thread_queue_Context_set_do_nothing_enqueue_callout( queue_context ); _Thread_queue_Context_set_deadlock_callout( queue_context, _Thread_queue_Deadlock_fatal ); _Thread_queue_Context_set_ISR_level( queue_context, level ); _Thread_queue_Enqueue( &mutex->Queue.Queue, MUTEX_TQ_OPERATIONS, executing, queue_context ); }
Status_Control _CORE_mutex_Seize_slow( CORE_mutex_Control *the_mutex, const Thread_queue_Operations *operations, Thread_Control *executing, bool wait, Thread_queue_Context *queue_context ) { if ( wait ) { _Thread_queue_Context_set_thread_state( queue_context, STATES_WAITING_FOR_MUTEX ); _Thread_queue_Context_set_do_nothing_enqueue_callout( queue_context ); _Thread_queue_Context_set_deadlock_callout( queue_context, _Thread_queue_Deadlock_status ); _Thread_queue_Enqueue( &the_mutex->Wait_queue.Queue, operations, executing, queue_context ); return _Thread_Wait_get_status( executing ); } else { _CORE_mutex_Release( the_mutex, queue_context ); return STATUS_UNAVAILABLE; } }
void _Thread_Join( Thread_Control *the_thread, States_Control waiting_for_join, Thread_Control *executing, Thread_queue_Context *queue_context ) { _Assert( the_thread != executing ); _Assert( _Thread_State_is_owner( the_thread ) ); #if defined(RTEMS_POSIX_API) executing->Wait.return_argument = NULL; #endif _Thread_queue_Context_set_thread_state( queue_context, waiting_for_join ); _Thread_queue_Enqueue( &the_thread->Join_queue.Queue, THREAD_JOIN_TQ_OPERATIONS, executing, queue_context ); }
rtems_status_code rtems_region_get_segment( rtems_id id, uintptr_t size, rtems_option option_set, rtems_interval timeout, void **segment ) { rtems_status_code status; Region_Control *the_region; if ( segment == NULL ) { return RTEMS_INVALID_ADDRESS; } *segment = NULL; if ( size == 0 ) { return RTEMS_INVALID_SIZE; } the_region = _Region_Get_and_lock( id ); if ( the_region == NULL ) { return RTEMS_INVALID_ID; } if ( size > the_region->maximum_segment_size ) { status = RTEMS_INVALID_SIZE; } else { void *the_segment; the_segment = _Region_Allocate_segment( the_region, size ); if ( the_segment != NULL ) { *segment = the_segment; status = RTEMS_SUCCESSFUL; } else if ( _Options_Is_no_wait( option_set ) ) { status = RTEMS_UNSATISFIED; } else { Thread_queue_Context queue_context; Thread_Control *executing; _Thread_queue_Context_initialize( &queue_context ); _Thread_queue_Acquire( &the_region->Wait_queue, &queue_context ); executing = _Thread_Executing; executing->Wait.count = size; executing->Wait.return_argument = segment; /* FIXME: This is a home grown condition variable */ _Thread_queue_Context_set_thread_state( &queue_context, STATES_WAITING_FOR_SEGMENT ); _Thread_queue_Context_set_timeout_ticks( &queue_context, timeout ); _Thread_queue_Context_set_enqueue_callout( &queue_context, _Region_Enqueue_callout ); _Thread_queue_Enqueue( &the_region->Wait_queue.Queue, the_region->wait_operations, executing, &queue_context ); return _Status_Get_after_wait( executing ); } } _Region_Unlock( the_region ); return status; }
Status_Control _CORE_message_queue_Submit( CORE_message_queue_Control *the_message_queue, Thread_Control *executing, const void *buffer, size_t size, CORE_message_queue_Submit_types submit_type, bool wait, Thread_queue_Context *queue_context ) { CORE_message_queue_Buffer_control *the_message; Thread_Control *the_thread; if ( size > the_message_queue->maximum_message_size ) { _CORE_message_queue_Release( the_message_queue, queue_context ); return STATUS_MESSAGE_INVALID_SIZE; } /* * Is there a thread currently waiting on this message queue? */ the_thread = _CORE_message_queue_Dequeue_receiver( the_message_queue, buffer, size, submit_type, queue_context ); if ( the_thread != NULL ) { return STATUS_SUCCESSFUL; } /* * No one waiting on the message queue at this time, so attempt to * queue the message up for a future receive. */ the_message = _CORE_message_queue_Allocate_message_buffer( the_message_queue ); if ( the_message ) { _CORE_message_queue_Insert_message( the_message_queue, the_message, buffer, size, submit_type ); #if defined(RTEMS_SCORE_COREMSG_ENABLE_NOTIFICATION) /* * According to POSIX, does this happen before or after the message * is actually enqueued. It is logical to think afterwards, because * the message is actually in the queue at this point. */ if ( the_message_queue->number_of_pending_messages == 1 && the_message_queue->notify_handler != NULL ) { ( *the_message_queue->notify_handler )( the_message_queue, queue_context ); } else { _CORE_message_queue_Release( the_message_queue, queue_context ); } #else _CORE_message_queue_Release( the_message_queue, queue_context ); #endif return STATUS_SUCCESSFUL; } #if !defined(RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND) _CORE_message_queue_Release( the_message_queue, queue_context ); return STATUS_TOO_MANY; #else /* * No message buffers were available so we may need to return an * overflow error or block the sender until the message is placed * on the queue. */ if ( !wait ) { _CORE_message_queue_Release( the_message_queue, queue_context ); return STATUS_TOO_MANY; } /* * Do NOT block on a send if the caller is in an ISR. It is * deadly to block in an ISR. */ if ( _ISR_Is_in_progress() ) { _CORE_message_queue_Release( the_message_queue, queue_context ); return STATUS_MESSAGE_QUEUE_WAIT_IN_ISR; } /* * WARNING!! executing should NOT be used prior to this point. * Thus the unusual choice to open a new scope and declare * it as a variable. Doing this emphasizes how dangerous it * would be to use this variable prior to here. */ executing->Wait.return_argument_second.immutable_object = buffer; executing->Wait.option = (uint32_t) size; executing->Wait.count = submit_type; _Thread_queue_Context_set_thread_state( queue_context, STATES_WAITING_FOR_MESSAGE ); _Thread_queue_Context_set_do_nothing_enqueue_callout( queue_context ); _Thread_queue_Enqueue( &the_message_queue->Wait_queue.Queue, the_message_queue->operations, executing, queue_context ); return _Thread_Wait_get_status( executing ); #endif }