source: rtems/cpukit/posix/src/mqueuesendsupp.c @ 860c34e

4.104.114.95
Last change on this file since 860c34e was 860c34e, checked in by Glenn Humphrey <glenn.humphrey@…>, on 11/30/07 at 20:34:13

2007-11-30 Glenn Humphrey <glenn.humphrey@…>

  • posix/include/rtems/posix/mutex.h, posix/include/rtems/posix/semaphore.h, posix/src/cancel.c, posix/src/conddestroy.c, posix/src/condsignalsupp.c, posix/src/condwaitsupp.c, posix/src/keydelete.c, posix/src/keygetspecific.c, posix/src/keysetspecific.c, posix/src/mqueueclose.c, posix/src/mqueuegetattr.c, posix/src/mqueuenotify.c, posix/src/mqueuerecvsupp.c, posix/src/mqueuesendsupp.c, posix/src/mqueuesetattr.c, posix/src/mqueuetranslatereturncode.c, posix/src/mutexdestroy.c, posix/src/mutexgetprioceiling.c, posix/src/mutexinit.c, posix/src/mutexlocksupp.c, posix/src/mutexsetprioceiling.c, posix/src/mutexunlock.c, posix/src/pbarrierdestroy.c, posix/src/pbarriertranslatereturncode.c, posix/src/pbarrierwait.c, posix/src/prwlockdestroy.c, posix/src/prwlockrdlock.c, posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c, posix/src/prwlocktranslatereturncode.c, posix/src/prwlocktryrdlock.c, posix/src/prwlocktrywrlock.c, posix/src/prwlockunlock.c, posix/src/prwlockwrlock.c, posix/src/pspindestroy.c, posix/src/pspinlock.c, posix/src/pspinlocktranslatereturncode.c, posix/src/pspintrylock.c, posix/src/pspinunlock.c, posix/src/pthreaddetach.c, posix/src/pthreadequal.c, posix/src/pthreadgetschedparam.c, posix/src/pthreadjoin.c, posix/src/pthreadkill.c, posix/src/pthreadsetschedparam.c, posix/src/ptimer1.c, posix/src/semaphorewaitsupp.c, posix/src/semclose.c, posix/src/semdestroy.c, posix/src/semgetvalue.c, posix/src/sempost.c, posix/src/types.c, rtems/src/msgqtranslatereturncode.c, rtems/src/semobtain.c, rtems/src/timerfireafter.c, score/include/rtems/system.h, score/include/rtems/score/corebarrier.h, score/include/rtems/score/coremsg.h, score/include/rtems/score/coremutex.h, score/include/rtems/score/coresem.h: Restructed to move the OBJECTS_LOCAL case to the top of the switch statement and eliminate the fall-through return of POSIX_BOTTOM_REACHED. These changes produced simplier assembly code and allowed for complete test coverage. Also applied some consistency to the functions that translate the core status codes to POSIX status codes.
  • posix/src/mutextranslatereturncode.c, posix/src/semaphoretranslatereturncode.c: New files.
  • posix/src/mutexfromcorestatus.c: Removed.
  • Property mode set to 100644
File size: 2.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
36/*PAGE
37 *
38 *  _POSIX_Message_queue_Send_support
39 */
40
41int _POSIX_Message_queue_Send_support(
42  mqd_t               mqdes,
43  const char         *msg_ptr,
44  size_t              msg_len,
45  uint32_t            msg_prio,
46  Watchdog_Interval   timeout
47)
48{
49  POSIX_Message_queue_Control    *the_mq;
50  POSIX_Message_queue_Control_fd *the_mq_fd;
51  Objects_Locations               location;
52  CORE_message_queue_Status       msg_status;
53
54  /*
55   * Validate the priority.
56   * XXX - Do not validate msg_prio is not less than 0.
57   */
58
59  if ( msg_prio > MQ_PRIO_MAX )
60    rtems_set_errno_and_return_minus_one( EINVAL );
61
62  the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location );
63  switch ( location ) {
64
65    case OBJECTS_LOCAL:
66      if ( (the_mq_fd->oflag & O_ACCMODE) == O_RDONLY ) {
67        _Thread_Enable_dispatch();
68        rtems_set_errno_and_return_minus_one( EBADF );
69      }
70
71      the_mq = the_mq_fd->Queue;
72
73      msg_status = _CORE_message_queue_Submit(
74        &the_mq->Message_queue,
75        msg_ptr,
76        msg_len,
77        mqdes,      /* mqd_t is an object id */
78        NULL,
79        _POSIX_Message_queue_Priority_to_core( msg_prio ),
80         (the_mq_fd->oflag & O_NONBLOCK) ? FALSE : TRUE,
81        timeout    /* no timeout */
82      );
83
84      _Thread_Enable_dispatch();
85
86      /*
87       *  If we had to block, then this is where the task returns
88       *  after it wakes up.  The returned status is correct for
89       *  non-blocking operations but if we blocked, then we need
90       *  to look at the status in our TCB.
91       */
92
93      if ( msg_status == CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_WAIT )
94        msg_status = _Thread_Executing->Wait.return_code;
95
96      if ( !msg_status )
97        return msg_status;
98
99      rtems_set_errno_and_return_minus_one(
100        _POSIX_Message_queue_Translate_core_message_queue_return_code(
101          msg_status
102        )
103      );
104
105#if defined(RTEMS_MULTIPROCESSING)
106    case OBJECTS_REMOTE:
107#endif
108    case OBJECTS_ERROR:
109      break;
110  }
111
112  rtems_set_errno_and_return_minus_one( EBADF );
113}
Note: See TracBrowser for help on using the repository browser.