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-2007. |
---|
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.com/license/LICENSE. |
---|
20 | * |
---|
21 | * $Id$ |
---|
22 | */ |
---|
23 | |
---|
24 | #if HAVE_CONFIG_H |
---|
25 | #include "config.h" |
---|
26 | #endif |
---|
27 | |
---|
28 | #include <stdarg.h> |
---|
29 | |
---|
30 | #include <pthread.h> |
---|
31 | #include <limits.h> |
---|
32 | #include <errno.h> |
---|
33 | #include <fcntl.h> |
---|
34 | #include <mqueue.h> |
---|
35 | #include <sys/types.h> |
---|
36 | #include <signal.h> |
---|
37 | |
---|
38 | #include <rtems/system.h> |
---|
39 | #include <rtems/score/watchdog.h> |
---|
40 | #include <rtems/seterr.h> |
---|
41 | #include <rtems/posix/mqueue.h> |
---|
42 | #include <rtems/posix/time.h> |
---|
43 | |
---|
44 | /* |
---|
45 | * _POSIX_Message_queue_Notify_handler |
---|
46 | * |
---|
47 | */ |
---|
48 | |
---|
49 | static void _POSIX_Message_queue_Notify_handler( |
---|
50 | void *user_data |
---|
51 | ) |
---|
52 | { |
---|
53 | POSIX_Message_queue_Control *the_mq; |
---|
54 | |
---|
55 | the_mq = user_data; |
---|
56 | |
---|
57 | kill( getpid(), the_mq->notification.sigev_signo ); |
---|
58 | |
---|
59 | _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL, NULL ); |
---|
60 | } |
---|
61 | |
---|
62 | /* |
---|
63 | * 15.2.6 Notify Process that a Message is Available on a Queue, |
---|
64 | * P1003.1b-1993, p. 280 |
---|
65 | */ |
---|
66 | |
---|
67 | int mq_notify( |
---|
68 | mqd_t mqdes, |
---|
69 | const struct sigevent *notification |
---|
70 | ) |
---|
71 | { |
---|
72 | POSIX_Message_queue_Control *the_mq; |
---|
73 | POSIX_Message_queue_Control_fd *the_mq_fd; |
---|
74 | Objects_Locations location; |
---|
75 | |
---|
76 | the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location ); |
---|
77 | switch ( location ) { |
---|
78 | |
---|
79 | case OBJECTS_LOCAL: |
---|
80 | the_mq = the_mq_fd->Queue; |
---|
81 | |
---|
82 | if ( notification ) { |
---|
83 | if ( _CORE_message_queue_Is_notify_enabled( &the_mq->Message_queue ) ) { |
---|
84 | _Thread_Enable_dispatch(); |
---|
85 | rtems_set_errno_and_return_minus_one( EBUSY ); |
---|
86 | } |
---|
87 | |
---|
88 | _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL, NULL ); |
---|
89 | |
---|
90 | the_mq->notification = *notification; |
---|
91 | |
---|
92 | _CORE_message_queue_Set_notify( |
---|
93 | &the_mq->Message_queue, |
---|
94 | _POSIX_Message_queue_Notify_handler, |
---|
95 | the_mq |
---|
96 | ); |
---|
97 | } else { |
---|
98 | |
---|
99 | _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL, NULL ); |
---|
100 | |
---|
101 | } |
---|
102 | |
---|
103 | _Thread_Enable_dispatch(); |
---|
104 | return 0; |
---|
105 | |
---|
106 | #if defined(RTEMS_MULTIPROCESSING) |
---|
107 | case OBJECTS_REMOTE: |
---|
108 | #endif |
---|
109 | case OBJECTS_ERROR: |
---|
110 | break; |
---|
111 | } |
---|
112 | |
---|
113 | rtems_set_errno_and_return_minus_one( EBADF ); |
---|
114 | } |
---|