source: rtems/cpukit/posix/src/mqueuecreatesupp.c @ 21789a21

5
Last change on this file since 21789a21 was 21789a21, checked in by Sebastian Huber <sebastian.huber@…>, on 07/28/15 at 12:45:42

score: Rename _POSIX_Absolute_timeout_to_ticks()

Rename _POSIX_Absolute_timeout_to_ticks() to
_TOD_Absolute_timeout_to_ticks() and move it to the score directory.
Delete empty <rtems/posix/time.h>.

  • Property mode set to 100644
File size: 3.8 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 *  COPYRIGHT (c) 1989-2009.
15 *  On-Line Applications Research Corporation (OAR).
16 *
17 *  The license and distribution terms for this file may be
18 *  found in the file LICENSE in this distribution or at
19 *  http://www.rtems.org/license/LICENSE.
20 */
21
22#if HAVE_CONFIG_H
23#include "config.h"
24#endif
25
26#include <string.h>
27#include <stdarg.h>
28#include <stdlib.h>
29
30#include <pthread.h>
31#include <limits.h>
32#include <errno.h>
33#include <fcntl.h>
34#include <mqueue.h>
35
36#include <rtems/system.h>
37#include <rtems/score/watchdog.h>
38#include <rtems/score/wkspace.h>
39#include <rtems/seterr.h>
40#include <rtems/posix/mqueueimpl.h>
41
42/*
43 *  _POSIX_Message_queue_Create_support
44 *
45 *  This routine does the actual creation and initialization of
46 *  a poxix message queue.
47 */
48
49int _POSIX_Message_queue_Create_support(
50  const char                    *name_arg,
51  size_t                         name_len,
52  int                            pshared,
53  struct mq_attr                *attr_ptr,
54  POSIX_Message_queue_Control  **message_queue
55)
56{
57  POSIX_Message_queue_Control   *the_mq;
58  CORE_message_queue_Attributes *the_mq_attr;
59  struct mq_attr                 attr;
60  char                          *name;
61
62  /* length of name has already been validated */
63
64  /*
65   *  There is no real basis for the default values.  They will work
66   *  but were not compared against any existing implementation for
67   *  compatibility.  See README.mqueue for an example program we
68   *  think will print out the defaults.  Report anything you find with it.
69   */
70  if ( attr_ptr == NULL ) {
71    attr.mq_maxmsg  = 10;
72    attr.mq_msgsize = 16;
73  } else {
74    if ( attr_ptr->mq_maxmsg <= 0 ){
75      rtems_set_errno_and_return_minus_one( EINVAL );
76    }
77
78    if ( attr_ptr->mq_msgsize <= 0 ){
79      rtems_set_errno_and_return_minus_one( EINVAL );
80    }
81
82    attr = *attr_ptr;
83  }
84
85  the_mq = _POSIX_Message_queue_Allocate();
86  if ( !the_mq ) {
87    _Objects_Allocator_unlock();
88    rtems_set_errno_and_return_minus_one( ENFILE );
89  }
90
91  /*
92   * Make a copy of the user's string for name just in case it was
93   * dynamically constructed.
94   */
95  name = _Workspace_String_duplicate( name_arg, name_len );
96  if ( !name ) {
97    _POSIX_Message_queue_Free( the_mq );
98    _Objects_Allocator_unlock();
99    rtems_set_errno_and_return_minus_one( ENOMEM );
100  }
101
102  the_mq->process_shared  = pshared;
103  the_mq->named = true;
104  the_mq->open_count = 1;
105  the_mq->linked = true;
106
107  /*
108   *  NOTE: That thread blocking discipline should be based on the
109   *  current scheduling policy.
110   *
111   *  Joel: Cite POSIX or OpenGroup on above statement so we can determine
112   *        if it is a real requirement.
113   */
114  the_mq_attr = &the_mq->Message_queue.Attributes;
115  the_mq_attr->discipline = CORE_MESSAGE_QUEUE_DISCIPLINES_FIFO;
116
117  if ( !_CORE_message_queue_Initialize(
118           &the_mq->Message_queue,
119           the_mq_attr,
120           attr.mq_maxmsg,
121           attr.mq_msgsize
122      ) ) {
123
124    _POSIX_Message_queue_Free( the_mq );
125    _Workspace_Free(name);
126    _Objects_Allocator_unlock();
127    rtems_set_errno_and_return_minus_one( ENOSPC );
128  }
129
130  _Objects_Open_string(
131    &_POSIX_Message_queue_Information,
132    &the_mq->Object,
133    name
134  );
135
136  *message_queue = the_mq;
137
138  _Objects_Allocator_unlock();
139  return 0;
140}
Note: See TracBrowser for help on using the repository browser.