[4dc89814] | 1 | /* |
---|
| 2 | * NOTE: The structure of the routines is identical to that of POSIX |
---|
| 3 | * Message_queues to leave the option of having unnamed message |
---|
| 4 | * queues at a future date. They are currently not part of the |
---|
| 5 | * POSIX standard but unnamed message_queues are. This is also |
---|
| 6 | * the reason for the apparently unnecessary tracking of |
---|
| 7 | * the process_shared attribute. [In addition to the fact that |
---|
| 8 | * it would be trivial to add pshared to the mq_attr structure |
---|
| 9 | * and have process private message queues.] |
---|
| 10 | * |
---|
| 11 | * This code ignores the O_RDONLY/O_WRONLY/O_RDWR flag at open |
---|
| 12 | * time. |
---|
| 13 | * |
---|
| 14 | * $Id$ |
---|
| 15 | */ |
---|
| 16 | |
---|
| 17 | #include <stdarg.h> |
---|
| 18 | |
---|
| 19 | #include <pthread.h> |
---|
| 20 | #include <limits.h> |
---|
| 21 | #include <errno.h> |
---|
| 22 | #include <fcntl.h> |
---|
| 23 | #include <mqueue.h> |
---|
| 24 | |
---|
| 25 | #include <rtems/system.h> |
---|
| 26 | #include <rtems/score/watchdog.h> |
---|
| 27 | #include <rtems/posix/seterr.h> |
---|
| 28 | #include <rtems/posix/mqueue.h> |
---|
| 29 | #include <rtems/posix/time.h> |
---|
| 30 | |
---|
| 31 | /*PAGE |
---|
| 32 | * |
---|
| 33 | * _POSIX_Message_queue_Create_support |
---|
| 34 | */ |
---|
| 35 | |
---|
| 36 | int _POSIX_Message_queue_Create_support( |
---|
| 37 | const char *name, |
---|
| 38 | int pshared, |
---|
| 39 | unsigned int oflag, |
---|
| 40 | struct mq_attr *attr, |
---|
| 41 | POSIX_Message_queue_Control **message_queue |
---|
| 42 | ) |
---|
| 43 | { |
---|
| 44 | POSIX_Message_queue_Control *the_mq; |
---|
| 45 | |
---|
| 46 | _Thread_Disable_dispatch(); |
---|
| 47 | |
---|
| 48 | the_mq = _POSIX_Message_queue_Allocate(); |
---|
| 49 | |
---|
| 50 | if ( !the_mq ) { |
---|
| 51 | _Thread_Enable_dispatch(); |
---|
| 52 | set_errno_and_return_minus_one( ENFILE ); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 56 | if ( pshared == PTHREAD_PROCESS_SHARED && |
---|
| 57 | !( _Objects_MP_Allocate_and_open( &_POSIX_Message_queue_Information, 0, |
---|
| 58 | the_mq->Object.id, FALSE ) ) ) { |
---|
| 59 | _POSIX_Message_queue_Free( the_mq ); |
---|
| 60 | _Thread_Enable_dispatch(); |
---|
| 61 | set_errno_and_return_minus_one( ENFILE ); |
---|
| 62 | } |
---|
| 63 | #endif |
---|
| 64 | |
---|
| 65 | the_mq->process_shared = pshared; |
---|
| 66 | |
---|
| 67 | if ( name ) { |
---|
| 68 | the_mq->named = TRUE; |
---|
| 69 | the_mq->open_count = 1; |
---|
| 70 | the_mq->linked = TRUE; |
---|
| 71 | } |
---|
| 72 | else |
---|
| 73 | the_mq->named = FALSE; |
---|
| 74 | |
---|
| 75 | if ( oflag & O_NONBLOCK ) |
---|
| 76 | the_mq->blocking = FALSE; |
---|
| 77 | else |
---|
| 78 | the_mq->blocking = TRUE; |
---|
| 79 | |
---|
| 80 | /* XXX |
---|
| 81 | * |
---|
| 82 | * Note that this should be based on the current scheduling policy. |
---|
| 83 | */ |
---|
| 84 | |
---|
| 85 | /* XXX |
---|
| 86 | * |
---|
| 87 | * Message and waiting disciplines are not distinguished. |
---|
| 88 | */ |
---|
| 89 | /* |
---|
| 90 | the_mq_attr->message_discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; |
---|
| 91 | the_mq_attr->waiting_discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; |
---|
| 92 | */ |
---|
| 93 | |
---|
| 94 | the_mq->Message_queue.Attributes.discipline = |
---|
| 95 | CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO; |
---|
| 96 | |
---|
| 97 | if ( ! _CORE_message_queue_Initialize( |
---|
| 98 | &the_mq->Message_queue, |
---|
| 99 | OBJECTS_POSIX_MESSAGE_QUEUES, |
---|
| 100 | &the_mq->Message_queue.Attributes, |
---|
| 101 | attr->mq_maxmsg, |
---|
| 102 | attr->mq_msgsize, |
---|
| 103 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 104 | _POSIX_Message_queue_MP_Send_extract_proxy |
---|
| 105 | #else |
---|
| 106 | NULL |
---|
| 107 | #endif |
---|
| 108 | ) ) { |
---|
| 109 | |
---|
| 110 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 111 | if ( pshared == PTHREAD_PROCESS_SHARED ) |
---|
| 112 | _Objects_MP_Close( &_POSIX_Message_queue_Information, the_mq->Object.id ); |
---|
| 113 | #endif |
---|
| 114 | |
---|
| 115 | _POSIX_Message_queue_Free( the_mq ); |
---|
| 116 | _Thread_Enable_dispatch(); |
---|
| 117 | set_errno_and_return_minus_one( ENOSPC ); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | /* XXX - need Names to be a string!!! */ |
---|
| 122 | _Objects_Open( |
---|
| 123 | &_POSIX_Message_queue_Information, |
---|
| 124 | &the_mq->Object, |
---|
| 125 | (char *) name |
---|
| 126 | ); |
---|
| 127 | |
---|
| 128 | *message_queue = the_mq; |
---|
| 129 | |
---|
| 130 | #if defined(RTEMS_MULTIPROCESSING) |
---|
| 131 | if ( pshared == PTHREAD_PROCESS_SHARED ) |
---|
| 132 | _POSIX_Message_queue_MP_Send_process_packet( |
---|
| 133 | POSIX_MESSAGE_QUEUE_MP_ANNOUNCE_CREATE, |
---|
| 134 | the_mq->Object.id, |
---|
| 135 | (char *) name, |
---|
| 136 | 0 /* Not used */ |
---|
| 137 | ); |
---|
| 138 | #endif |
---|
| 139 | |
---|
| 140 | _Thread_Enable_dispatch(); |
---|
| 141 | return 0; |
---|
| 142 | } |
---|
| 143 | |
---|