rtems_status_code _Message_queue_MP_Send_request_packet ( Message_queue_MP_Remote_operations operation, Objects_Id message_queue_id, const void *buffer, size_t *size_p, rtems_option option_set, rtems_interval timeout ) { Message_queue_MP_Packet *the_packet; switch ( operation ) { case MESSAGE_QUEUE_MP_SEND_REQUEST: case MESSAGE_QUEUE_MP_URGENT_REQUEST: case MESSAGE_QUEUE_MP_BROADCAST_REQUEST: case MESSAGE_QUEUE_MP_FLUSH_REQUEST: case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST: the_packet = _Message_queue_MP_Get_packet(); the_packet->Prefix.the_class = MP_PACKET_MESSAGE_QUEUE; the_packet->Prefix.length = MESSAGE_QUEUE_MP_PACKET_SIZE; if ( size_p ) the_packet->Prefix.length += *size_p; the_packet->Prefix.to_convert = MESSAGE_QUEUE_MP_PACKET_SIZE; /* * make sure message is not too big for our MPCI driver * We have to check it here instead of waiting for MPCI because * we are about to slam in the payload */ if (the_packet->Prefix.length > _MPCI_table->maximum_packet_size) { return RTEMS_INVALID_SIZE; } if (! _Options_Is_no_wait(option_set)) the_packet->Prefix.timeout = timeout; the_packet->operation = operation; the_packet->Prefix.id = message_queue_id; the_packet->option_set = option_set; /* * Copy the data into place if needed */ if (buffer) { the_packet->Buffer.size = *size_p; _CORE_message_queue_Copy_buffer( buffer, the_packet->Buffer.buffer, *size_p ); } return (rtems_status_code) _MPCI_Send_request_packet( _Objects_Get_node(message_queue_id), &the_packet->Prefix, STATES_WAITING_FOR_MESSAGE, RTEMS_TIMEOUT ); break; case MESSAGE_QUEUE_MP_RECEIVE_REQUEST: the_packet = _Message_queue_MP_Get_packet(); the_packet->Prefix.the_class = MP_PACKET_MESSAGE_QUEUE; the_packet->Prefix.length = MESSAGE_QUEUE_MP_PACKET_SIZE; the_packet->Prefix.to_convert = MESSAGE_QUEUE_MP_PACKET_SIZE; if (! _Options_Is_no_wait(option_set)) the_packet->Prefix.timeout = timeout; the_packet->operation = MESSAGE_QUEUE_MP_RECEIVE_REQUEST; the_packet->Prefix.id = message_queue_id; the_packet->option_set = option_set; the_packet->size = 0; /* just in case of an error */ _Thread_Executing->Wait.return_argument_second.immutable_object = buffer; _Thread_Executing->Wait.return_argument = size_p; return (rtems_status_code) _MPCI_Send_request_packet( _Objects_Get_node(message_queue_id), &the_packet->Prefix, STATES_WAITING_FOR_MESSAGE, RTEMS_TIMEOUT ); break; case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE: case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE: case MESSAGE_QUEUE_MP_EXTRACT_PROXY: case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE: case MESSAGE_QUEUE_MP_SEND_RESPONSE: case MESSAGE_QUEUE_MP_URGENT_RESPONSE: case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE: case MESSAGE_QUEUE_MP_FLUSH_RESPONSE: case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE: break; } return RTEMS_SUCCESSFUL; }
void _Message_queue_MP_Process_packet ( rtems_packet_prefix *the_packet_prefix ) { Message_queue_MP_Packet *the_packet; Thread_Control *the_thread; bool ignored; the_packet = (Message_queue_MP_Packet *) the_packet_prefix; switch ( the_packet->operation ) { case MESSAGE_QUEUE_MP_ANNOUNCE_CREATE: ignored = _Objects_MP_Allocate_and_open( &_Message_queue_Information, the_packet->name, the_packet->Prefix.id, true ); _MPCI_Return_packet( the_packet_prefix ); break; case MESSAGE_QUEUE_MP_ANNOUNCE_DELETE: _Objects_MP_Close( &_Message_queue_Information, the_packet->Prefix.id ); _MPCI_Return_packet( the_packet_prefix ); break; case MESSAGE_QUEUE_MP_EXTRACT_PROXY: the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id ); if (! _Thread_Is_null( the_thread ) ) _Thread_queue_Extract( the_thread ); _MPCI_Return_packet( the_packet_prefix ); break; case MESSAGE_QUEUE_MP_RECEIVE_REQUEST: the_packet->Prefix.return_code = rtems_message_queue_receive( the_packet->Prefix.id, the_packet->Buffer.buffer, &the_packet->size, the_packet->option_set, the_packet->Prefix.timeout ); if ( the_packet->Prefix.return_code != RTEMS_PROXY_BLOCKING ) _Message_queue_MP_Send_response_packet( MESSAGE_QUEUE_MP_RECEIVE_RESPONSE, the_packet->Prefix.id, _Thread_Executing ); break; case MESSAGE_QUEUE_MP_RECEIVE_RESPONSE: the_thread = _MPCI_Process_response( the_packet_prefix ); if (the_packet->Prefix.return_code == RTEMS_SUCCESSFUL) { *(size_t *) the_thread->Wait.return_argument = the_packet->size; _CORE_message_queue_Copy_buffer( the_packet->Buffer.buffer, the_thread->Wait.return_argument_second.mutable_object, the_packet->size ); } _MPCI_Return_packet( the_packet_prefix ); break; case MESSAGE_QUEUE_MP_SEND_REQUEST: the_packet->Prefix.return_code = rtems_message_queue_send( the_packet->Prefix.id, the_packet->Buffer.buffer, the_packet->Buffer.size ); _Message_queue_MP_Send_response_packet( MESSAGE_QUEUE_MP_SEND_RESPONSE, the_packet->Prefix.id, _Thread_Executing ); break; case MESSAGE_QUEUE_MP_SEND_RESPONSE: case MESSAGE_QUEUE_MP_URGENT_RESPONSE: the_thread = _MPCI_Process_response( the_packet_prefix ); _MPCI_Return_packet( the_packet_prefix ); break; case MESSAGE_QUEUE_MP_URGENT_REQUEST: the_packet->Prefix.return_code = rtems_message_queue_urgent( the_packet->Prefix.id, the_packet->Buffer.buffer, the_packet->Buffer.size ); _Message_queue_MP_Send_response_packet( MESSAGE_QUEUE_MP_URGENT_RESPONSE, the_packet->Prefix.id, _Thread_Executing ); break; case MESSAGE_QUEUE_MP_BROADCAST_REQUEST: the_packet->Prefix.return_code = rtems_message_queue_broadcast( the_packet->Prefix.id, the_packet->Buffer.buffer, the_packet->Buffer.size, &the_packet->count ); _Message_queue_MP_Send_response_packet( MESSAGE_QUEUE_MP_BROADCAST_RESPONSE, the_packet->Prefix.id, _Thread_Executing ); break; case MESSAGE_QUEUE_MP_BROADCAST_RESPONSE: case MESSAGE_QUEUE_MP_FLUSH_RESPONSE: case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE: the_thread = _MPCI_Process_response( the_packet_prefix ); *(uint32_t *) the_thread->Wait.return_argument = the_packet->count; _MPCI_Return_packet( the_packet_prefix ); break; case MESSAGE_QUEUE_MP_FLUSH_REQUEST: the_packet->Prefix.return_code = rtems_message_queue_flush( the_packet->Prefix.id, &the_packet->count ); _Message_queue_MP_Send_response_packet( MESSAGE_QUEUE_MP_FLUSH_RESPONSE, the_packet->Prefix.id, _Thread_Executing ); break; case MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_REQUEST: the_packet->Prefix.return_code = rtems_message_queue_get_number_pending( the_packet->Prefix.id, &the_packet->count ); _Message_queue_MP_Send_response_packet( MESSAGE_QUEUE_MP_GET_NUMBER_PENDING_RESPONSE, the_packet->Prefix.id, _Thread_Executing ); break; } }
void _CORE_message_queue_Seize( CORE_message_queue_Control *the_message_queue, Thread_Control *executing, Objects_Id id, void *buffer, size_t *size_p, bool wait, Watchdog_Interval timeout ) { ISR_Level level; CORE_message_queue_Buffer_control *the_message; executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; _ISR_Disable( level ); the_message = _CORE_message_queue_Get_pending_message( the_message_queue ); if ( the_message != NULL ) { the_message_queue->number_of_pending_messages -= 1; _ISR_Enable( level ); *size_p = the_message->Contents.size; executing->Wait.count = _CORE_message_queue_Get_message_priority( the_message ); _CORE_message_queue_Copy_buffer( the_message->Contents.buffer, buffer, *size_p ); #if !defined(RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND) /* * There is not an API with blocking sends enabled. * So return immediately. */ _CORE_message_queue_Free_message_buffer(the_message_queue, the_message); return; #else { Thread_Control *the_thread; /* * There could be a thread waiting to send a message. If there * is not, then we can go ahead and free the buffer. * * NOTE: If we note that the queue was not full before this receive, * then we can avoid this dequeue. */ the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue ); if ( !the_thread ) { _CORE_message_queue_Free_message_buffer( the_message_queue, the_message ); return; } /* * There was a thread waiting to send a message. This code * puts the messages in the message queue on behalf of the * waiting task. */ _CORE_message_queue_Set_message_priority( the_message, the_thread->Wait.count ); the_message->Contents.size = (size_t) the_thread->Wait.option; _CORE_message_queue_Copy_buffer( the_thread->Wait.return_argument_second.immutable_object, the_message->Contents.buffer, the_message->Contents.size ); _CORE_message_queue_Insert_message( the_message_queue, the_message, _CORE_message_queue_Get_message_priority( the_message ) ); return; } #endif } if ( !wait ) { _ISR_Enable( level ); executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT; return; } _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue ); executing->Wait.queue = &the_message_queue->Wait_queue; executing->Wait.id = id; executing->Wait.return_argument_second.mutable_object = buffer; executing->Wait.return_argument = size_p; /* Wait.count will be filled in with the message priority */ _ISR_Enable( level ); _Thread_queue_Enqueue( &the_message_queue->Wait_queue, executing, STATES_WAITING_FOR_MESSAGE, timeout ); }
CORE_message_queue_Status _CORE_message_queue_Broadcast( CORE_message_queue_Control *the_message_queue, const void *buffer, size_t size, #if defined(RTEMS_MULTIPROCESSING) Objects_Id id, CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, #else Objects_Id id __attribute__((unused)), CORE_message_queue_API_mp_support_callout api_message_queue_mp_support __attribute__((unused)), #endif uint32_t *count ) { Thread_Control *the_thread; uint32_t number_broadcasted; Thread_Wait_information *waitp; if ( size > the_message_queue->maximum_message_size ) { return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE; } /* * If there are pending messages, then there can't be threads * waiting for us to send them a message. * * NOTE: This check is critical because threads can block on * send and receive and this ensures that we are broadcasting * the message to threads waiting to receive -- not to send. */ if ( the_message_queue->number_of_pending_messages != 0 ) { *count = 0; return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; } /* * There must be no pending messages if there is a thread waiting to * receive a message. */ number_broadcasted = 0; while ((the_thread = _Thread_queue_Dequeue(&the_message_queue->Wait_queue))) { waitp = &the_thread->Wait; number_broadcasted += 1; _CORE_message_queue_Copy_buffer( buffer, waitp->return_argument_second.mutable_object, size ); *(size_t *) the_thread->Wait.return_argument = size; #if defined(RTEMS_MULTIPROCESSING) if ( !_Objects_Is_local_id( the_thread->Object.id ) ) (*api_message_queue_mp_support) ( the_thread, id ); #endif } *count = number_broadcasted; return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; }
CORE_message_queue_Status _CORE_message_queue_Submit( CORE_message_queue_Control *the_message_queue, Thread_Control *executing, const void *buffer, size_t size, Objects_Id id, #if defined(RTEMS_MULTIPROCESSING) CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, #else CORE_message_queue_API_mp_support_callout api_message_queue_mp_support RTEMS_UNUSED, #endif CORE_message_queue_Submit_types submit_type, bool wait, Watchdog_Interval timeout, ISR_lock_Context *lock_context ) { CORE_message_queue_Buffer_control *the_message; Thread_Control *the_thread; if ( size > the_message_queue->maximum_message_size ) { _ISR_lock_ISR_enable( lock_context ); return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE; } _CORE_message_queue_Acquire_critical( the_message_queue, lock_context ); /* * Is there a thread currently waiting on this message queue? */ the_thread = _CORE_message_queue_Dequeue_receiver( the_message_queue, buffer, size, submit_type, lock_context ); if ( the_thread != NULL ) { #if defined(RTEMS_MULTIPROCESSING) if ( !_Objects_Is_local_id( the_thread->Object.id ) ) (*api_message_queue_mp_support) ( the_thread, id ); _Thread_Dispatch_enable( _Per_CPU_Get() ); #endif return CORE_MESSAGE_QUEUE_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 ) { the_message->Contents.size = size; _CORE_message_queue_Set_message_priority( the_message, submit_type ); _CORE_message_queue_Copy_buffer( buffer, the_message->Contents.buffer, size ); _CORE_message_queue_Insert_message( the_message_queue, the_message, submit_type ); _CORE_message_queue_Release( the_message_queue, lock_context ); return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; } #if !defined(RTEMS_SCORE_COREMSG_ENABLE_BLOCKING_SEND) _CORE_message_queue_Release( the_message_queue, lock_context ); return CORE_MESSAGE_QUEUE_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, lock_context ); return CORE_MESSAGE_QUEUE_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, lock_context ); return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED; } /* * 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.id = id; executing->Wait.return_argument_second.immutable_object = buffer; executing->Wait.option = (uint32_t) size; executing->Wait.count = submit_type; _Thread_queue_Enqueue_critical( &the_message_queue->Wait_queue.Queue, the_message_queue->Wait_queue.operations, executing, STATES_WAITING_FOR_MESSAGE, timeout, CORE_MESSAGE_QUEUE_STATUS_TIMEOUT, lock_context ); #if defined(RTEMS_MULTIPROCESSING) _Thread_Dispatch_enable( _Per_CPU_Get() ); #endif return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT; #endif }
CORE_message_queue_Status _CORE_message_queue_Submit( CORE_message_queue_Control *the_message_queue, void *buffer, size_t size, Objects_Id id, CORE_message_queue_API_mp_support_callout api_message_queue_mp_support, CORE_message_queue_Submit_types submit_type, boolean wait, Watchdog_Interval timeout ) { ISR_Level level; CORE_message_queue_Buffer_control *the_message; Thread_Control *the_thread; if ( size > the_message_queue->maximum_message_size ) { return CORE_MESSAGE_QUEUE_STATUS_INVALID_SIZE; } /* * Is there a thread currently waiting on this message queue? */ if ( the_message_queue->number_of_pending_messages == 0 ) { the_thread = _Thread_queue_Dequeue( &the_message_queue->Wait_queue ); if ( the_thread ) { _CORE_message_queue_Copy_buffer( buffer, the_thread->Wait.return_argument, size ); *(size_t *)the_thread->Wait.return_argument_1 = size; the_thread->Wait.count = submit_type; #if defined(RTEMS_MULTIPROCESSING) if ( !_Objects_Is_local_id( the_thread->Object.id ) ) (*api_message_queue_mp_support) ( the_thread, id ); #endif return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; } } /* * No one waiting on the message queue at this time, so attempt to * queue the message up for a future receive. */ if ( the_message_queue->number_of_pending_messages < the_message_queue->maximum_pending_messages ) { the_message = _CORE_message_queue_Allocate_message_buffer( the_message_queue ); /* * NOTE: If the system is consistent, this error should never occur. */ if ( !the_message ) { return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED; } _CORE_message_queue_Copy_buffer( buffer, the_message->Contents.buffer, size ); the_message->Contents.size = size; the_message->priority = submit_type; _CORE_message_queue_Insert_message( the_message_queue, the_message, submit_type ); return CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL; } /* * 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 ) { return CORE_MESSAGE_QUEUE_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() ) { return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED; } /* * 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. */ { Thread_Control *executing = _Thread_Executing; _ISR_Disable( level ); _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue ); executing->Wait.queue = &the_message_queue->Wait_queue; executing->Wait.id = id; executing->Wait.return_argument = buffer; executing->Wait.option = size; executing->Wait.count = submit_type; _ISR_Enable( level ); _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout ); } return CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT; }