OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [posix/] [src/] [mqueuerecvsupp.c] - Blame information for rev 738

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
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: mqueuerecvsupp.c,v 1.2 2001-09-27 11:59:17 chris Exp $
15
 */
16
 
17
#include <stdarg.h>
18
 
19
#include <pthread.h>
20
#include <limits.h>
21
#include <errno.h>
22
#include <fcntl.h>
23
#include <mqueue.h>
24
 
25
#include <rtems/system.h>
26
#include <rtems/score/watchdog.h>
27
#include <rtems/posix/seterr.h>
28
#include <rtems/posix/mqueue.h>
29
#include <rtems/posix/time.h>
30
 
31
/*PAGE
32
 *
33
 *  _POSIX_Message_queue_Receive_support
34
 *
35
 *  NOTE: XXX Document how size, priority, length, and the buffer go
36
 *        through the layers.
37
 */
38
 
39
ssize_t _POSIX_Message_queue_Receive_support(
40
  mqd_t               mqdes,
41
  char               *msg_ptr,
42
  size_t              msg_len,
43
  unsigned int       *msg_prio,
44
  Watchdog_Interval   timeout
45
)
46
{
47
  register POSIX_Message_queue_Control *the_mq;
48
  Objects_Locations                     location;
49
  unsigned32                            length_out;
50
 
51
  the_mq = _POSIX_Message_queue_Get( mqdes, &location );
52
  switch ( location ) {
53
    case OBJECTS_ERROR:
54
      set_errno_and_return_minus_one( EBADF );
55
    case OBJECTS_REMOTE:
56
      _Thread_Dispatch();
57
      return POSIX_MP_NOT_IMPLEMENTED();
58
      set_errno_and_return_minus_one( EINVAL );
59
    case OBJECTS_LOCAL:
60
      if ( (the_mq->oflag & O_ACCMODE) == O_WRONLY ) {
61
        _Thread_Enable_dispatch();
62
        set_errno_and_return_minus_one( EBADF );
63
      }
64
 
65
      if ( msg_len < the_mq->Message_queue.maximum_message_size ) {
66
        _Thread_Enable_dispatch();
67
        set_errno_and_return_minus_one( EMSGSIZE );
68
      }
69
 
70
      /*
71
       *  Now if something goes wrong, we return a "length" of -1
72
       *  to indicate an error.
73
       */
74
 
75
      length_out = -1;
76
 
77
      _CORE_message_queue_Seize(
78
        &the_mq->Message_queue,
79
        mqdes,
80
        msg_ptr,
81
        &length_out,
82
        (the_mq->oflag & O_NONBLOCK) ? FALSE : TRUE,
83
        timeout
84
      );
85
 
86
      _Thread_Enable_dispatch();
87
      *msg_prio =
88
        _POSIX_Message_queue_Priority_from_core(_Thread_Executing->Wait.count);
89
 
90
      if ( !_Thread_Executing->Wait.return_code )
91
        return length_out;
92
 
93
      set_errno_and_return_minus_one(
94
        _POSIX_Message_queue_Translate_core_message_queue_return_code(
95
          _Thread_Executing->Wait.return_code
96
        )
97
      );
98
  }
99
  return POSIX_BOTTOM_REACHED();
100
}
101
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.