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

4.104.114.84.95
Last change on this file since e7bd66a7 was afc3a590, checked in by Ralf Corsepius <ralf.corsepius@…>, on 07/31/02 at 06:22:38

2002-07-31 Ralf Corsepius <corsepiu@…>

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