source: rtems/cpukit/posix/src/mqueuecreatesupp.c @ f22ebf0

4.104.114.84.95
Last change on this file since f22ebf0 was 53092d1, checked in by Joel Sherrill <joel.sherrill@…>, on 04/26/02 at 23:39:01

2001-04-26 Joel Sherrill <joel@…>

  • include/rtems/posix/mqueue.h, inline/rtems/posix/mqueue.inl, src/mqueue.c, src/mqueueclose.c, src/mqueuecreatesupp.c, src/mqueuegetattr.c, src/mqueuenotify.c, src/mqueueopen.c, src/mqueuerecvsupp.c, src/mqueuesendsupp.c, src/mqueuesetattr.c: Per PR81 reworked to add a message queue descriptor separate from the underlying message queue. This allows non-blocking to follow the "open" not the underlying queue.
  • Property mode set to 100644
File size: 4.1 KB
Line 
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#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <stdarg.h>
22
23#include <pthread.h>
24#include <limits.h>
25#include <errno.h>
26#include <fcntl.h>
27#include <mqueue.h>
28
29#include <rtems/system.h>
30#include <rtems/score/watchdog.h>
31#include <rtems/seterr.h>
32#include <rtems/posix/mqueue.h>
33#include <rtems/posix/time.h>
34
35/*PAGE
36 *
37 *  _POSIX_Message_queue_Create_support
38 *
39 *  This routine does the actual creation and initialization of
40 *  a poxix message queue. 
41 */
42 
43int _POSIX_Message_queue_Create_support(
44  const char                    *_name,
45  int                            pshared,
46  struct mq_attr                *attr_ptr,
47  POSIX_Message_queue_Control  **message_queue
48)
49{
50  POSIX_Message_queue_Control   *the_mq;
51  CORE_message_queue_Attributes *the_mq_attr;
52  struct mq_attr                 attr;
53  char *name;
54
55  _Thread_Disable_dispatch();
56 
57  /*
58   *  There is no real basis for the default values.  They will work
59   *  but were not compared against any existing implementation for
60   *  compatibility.  See README.mqueue for an example program we
61   *  think will print out the defaults.  Report anything you find with it.
62   */
63
64  if ( attr_ptr == NULL ) {
65    attr.mq_maxmsg  = 10;
66    attr.mq_msgsize = 16;
67  } else {
68    if ( attr_ptr->mq_maxmsg < 0 ){
69      _Thread_Enable_dispatch();
70      rtems_set_errno_and_return_minus_one( EINVAL );
71    }
72
73    if ( attr_ptr->mq_msgsize < 0 ){
74      _Thread_Enable_dispatch();
75      rtems_set_errno_and_return_minus_one( EINVAL );
76    }
77
78    attr = *attr_ptr;
79  }
80
81#if 0 && defined(RTEMS_MULTIPROCESSING)
82  if ( pshared == PTHREAD_PROCESS_SHARED &&
83       !( _Objects_MP_Allocate_and_open( &_POSIX_Message_queue_Information, 0,
84                            the_mq->Object.id, FALSE ) ) ) {
85    _POSIX_Message_queue_Free( the_mq );
86    _Thread_Enable_dispatch();
87    rtems_set_errno_and_return_minus_one( ENFILE );
88  }
89#endif
90 
91  the_mq = _POSIX_Message_queue_Allocate();
92  if ( !the_mq ) {
93    _Thread_Enable_dispatch();
94    rtems_set_errno_and_return_minus_one( ENFILE );
95  }
96 
97  the_mq->process_shared  = pshared;
98  the_mq->named = TRUE;
99  the_mq->open_count = 1;
100  the_mq->linked = TRUE;
101
102 
103  /* XXX
104   *
105   *  Note that thread blocking discipline should be based on the
106   *  current scheduling policy.
107   */
108
109  the_mq_attr = &the_mq->Message_queue.Attributes;
110  the_mq_attr->discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
111
112  if ( ! _CORE_message_queue_Initialize(
113           &the_mq->Message_queue,
114           OBJECTS_POSIX_MESSAGE_QUEUES,
115           the_mq_attr,
116           attr.mq_maxmsg,
117           attr.mq_msgsize,
118#if 0 && defined(RTEMS_MULTIPROCESSING)
119           _POSIX_Message_queue_MP_Send_extract_proxy
120#else
121           NULL
122#endif
123      ) ) {
124
125#if 0 && defined(RTEMS_MULTIPROCESSING)
126    if ( pshared == PTHREAD_PROCESS_SHARED )
127      _Objects_MP_Close( &_POSIX_Message_queue_Information, the_mq->Object.id );
128#endif
129 
130    _POSIX_Message_queue_Free( the_mq );
131    _Thread_Enable_dispatch();
132    rtems_set_errno_and_return_minus_one( ENOSPC );
133  }
134
135  name = malloc(256);
136  strcpy( name, _name );
137  _Objects_Open(
138    &_POSIX_Message_queue_Information,
139    &the_mq->Object,
140    (char *) name
141  );
142 
143  *message_queue = the_mq;
144 
145#if 0 && defined(RTEMS_MULTIPROCESSING)
146  if ( pshared == PTHREAD_PROCESS_SHARED )
147    _POSIX_Message_queue_MP_Send_process_packet(
148      POSIX_MESSAGE_QUEUE_MP_ANNOUNCE_CREATE,
149      the_mq->Object.id,
150      (char *) name,
151      0                          /* Not used */
152    );
153#endif
154 
155  _Thread_Enable_dispatch();
156  return 0;
157}
158
159
160
161
162
Note: See TracBrowser for help on using the repository browser.