File indexing completed on 2025-05-11 08:24:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 #ifdef HAVE_CONFIG_H
0038 #include "config.h"
0039 #endif
0040
0041 #include <rtems/posix/mqueueimpl.h>
0042 #include <rtems/posix/posixapi.h>
0043
0044 #include <fcntl.h>
0045
0046 THREAD_QUEUE_OBJECT_ASSERT(
0047 POSIX_Message_queue_Control,
0048 Message_queue.Wait_queue,
0049 POSIX_MESSAGE_QUEUE_CONTROL
0050 );
0051
0052
0053
0054
0055
0056
0057
0058
0059 ssize_t _POSIX_Message_queue_Receive_support(
0060 mqd_t mqdes,
0061 char *msg_ptr,
0062 size_t msg_len,
0063 unsigned int *msg_prio,
0064 const struct timespec *abstime,
0065 Thread_queue_Enqueue_callout enqueue_callout
0066 )
0067 {
0068 POSIX_Message_queue_Control *the_mq;
0069 Thread_queue_Context queue_context;
0070 size_t length_out;
0071 Thread_Control *executing;
0072 Status_Control status;
0073
0074 the_mq = _POSIX_Message_queue_Get( mqdes, &queue_context );
0075
0076 if ( the_mq == NULL ) {
0077 rtems_set_errno_and_return_minus_one( EBADF );
0078 }
0079
0080 if ( ( the_mq->oflag & O_ACCMODE ) == O_WRONLY ) {
0081 _ISR_lock_ISR_enable( &queue_context.Lock_context.Lock_context );
0082 rtems_set_errno_and_return_minus_one( EBADF );
0083 }
0084
0085 if ( msg_len < the_mq->Message_queue.maximum_message_size ) {
0086 _ISR_lock_ISR_enable( &queue_context.Lock_context.Lock_context );
0087 rtems_set_errno_and_return_minus_one( EMSGSIZE );
0088 }
0089
0090 _Thread_queue_Context_set_enqueue_callout( &queue_context, enqueue_callout );
0091 _Thread_queue_Context_set_timeout_argument( &queue_context, abstime, true );
0092
0093
0094
0095
0096
0097 length_out = -1;
0098
0099 _CORE_message_queue_Acquire_critical(
0100 &the_mq->Message_queue,
0101 &queue_context
0102 );
0103
0104 if ( the_mq->open_count == 0 ) {
0105 _CORE_message_queue_Release( &the_mq->Message_queue, &queue_context );
0106 rtems_set_errno_and_return_minus_one( EBADF );
0107 }
0108
0109
0110
0111
0112 executing = _Thread_Executing;
0113 status = _CORE_message_queue_Seize(
0114 &the_mq->Message_queue,
0115 executing,
0116 msg_ptr,
0117 &length_out,
0118 ( the_mq->oflag & O_NONBLOCK ) == 0,
0119 &queue_context
0120 );
0121
0122 if ( status != STATUS_SUCCESSFUL ) {
0123 rtems_set_errno_and_return_minus_one( _POSIX_Get_error( status ) );
0124 }
0125
0126 if ( msg_prio != NULL ) {
0127 *msg_prio = _POSIX_Message_queue_Priority_from_core(
0128 executing->Wait.count
0129 );
0130 }
0131
0132 return length_out;
0133 }