source: rtems/cpukit/posix/src/mqueuecreatesupp.c @ 3c465878

4.104.114.84.95
Last change on this file since 3c465878 was 3c465878, checked in by Joel Sherrill <joel.sherrill@…>, on 07/01/02 at 22:33:47

2002-07-01 Joel Sherrill <joel@…>

  • Mega patch merge to change the format of the object IDs to loosen the dependency between the SCORE and the various APIs. There was considerable work to simplify the object name management and it appears that the name_table field is no longer needed. This patch also includes the addition of the internal mutex which is currently only used to protect some types of allocation and deallocation. This significantly can reduce context switch latency under certain circumstances. In particular, some heap/region operations were O(n) and had dispatching disabled. This should help enormously. With this merge, the patch is not as clean as it should be. In particular, the documentation has not been modified to reflect the new object ID layout, the IDs in the test screens are not updated, and _Objects_Get_information needs to be a real routine not inlined. As part of this patch a lot of MP code for thread/proxy blocking was made conditional and cleaned up.
  • include/rtems/posix/key.h, src/cond.c, src/condinit.c, src/intr.c, src/key.c, src/keycreate.c, src/keydelete.c, src/killinfo.c, src/mqueue.c, src/mqueuecreatesupp.c, src/mutex.c, src/mutexinit.c, src/psignal.c, src/pthread.c, src/semaphore.c, src/semaphorecreatesupp.c: Modified as part of above.
  • Property mode set to 100644
File size: 3.9 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           the_mq_attr,
115           attr.mq_maxmsg,
116           attr.mq_msgsize
117      ) ) {
118
119#if 0 && defined(RTEMS_MULTIPROCESSING)
120    if ( pshared == PTHREAD_PROCESS_SHARED )
121      _Objects_MP_Close( &_POSIX_Message_queue_Information, the_mq->Object.id );
122#endif
123 
124    _POSIX_Message_queue_Free( the_mq );
125    _Thread_Enable_dispatch();
126    rtems_set_errno_and_return_minus_one( ENOSPC );
127  }
128
129  name = malloc(256);
130  strcpy( name, _name );
131  _Objects_Open(
132    &_POSIX_Message_queue_Information,
133    &the_mq->Object,
134    (char *) name
135  );
136 
137  *message_queue = the_mq;
138 
139#if 0 && defined(RTEMS_MULTIPROCESSING)
140  if ( pshared == PTHREAD_PROCESS_SHARED )
141    _POSIX_Message_queue_MP_Send_process_packet(
142      POSIX_MESSAGE_QUEUE_MP_ANNOUNCE_CREATE,
143      the_mq->Object.id,
144      (char *) name,
145      0                          /* Not used */
146    );
147#endif
148 
149  _Thread_Enable_dispatch();
150  return 0;
151}
152
153
154
155
156
Note: See TracBrowser for help on using the repository browser.