1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Notify Process that a Message is Available on a Queue |
---|
5 | * @ingroup POSIX_MQUEUE |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * COPYRIGHT (c) 1989-2007. |
---|
10 | * On-Line Applications Research Corporation (OAR). |
---|
11 | * |
---|
12 | * The license and distribution terms for this file may be |
---|
13 | * found in the file LICENSE in this distribution or at |
---|
14 | * http://www.rtems.com/license/LICENSE. |
---|
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 | #include <sys/types.h> |
---|
29 | #include <signal.h> |
---|
30 | |
---|
31 | #include <rtems/system.h> |
---|
32 | #include <rtems/score/watchdog.h> |
---|
33 | #include <rtems/seterr.h> |
---|
34 | #include <rtems/posix/mqueue.h> |
---|
35 | #include <rtems/posix/time.h> |
---|
36 | |
---|
37 | /* |
---|
38 | * _POSIX_Message_queue_Notify_handler |
---|
39 | * |
---|
40 | */ |
---|
41 | |
---|
42 | static void _POSIX_Message_queue_Notify_handler( |
---|
43 | void *user_data |
---|
44 | ) |
---|
45 | { |
---|
46 | POSIX_Message_queue_Control *the_mq; |
---|
47 | |
---|
48 | the_mq = user_data; |
---|
49 | |
---|
50 | kill( getpid(), the_mq->notification.sigev_signo ); |
---|
51 | |
---|
52 | _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL, NULL ); |
---|
53 | } |
---|
54 | |
---|
55 | int mq_notify( |
---|
56 | mqd_t mqdes, |
---|
57 | const struct sigevent *notification |
---|
58 | ) |
---|
59 | { |
---|
60 | POSIX_Message_queue_Control *the_mq; |
---|
61 | POSIX_Message_queue_Control_fd *the_mq_fd; |
---|
62 | Objects_Locations location; |
---|
63 | |
---|
64 | the_mq_fd = _POSIX_Message_queue_Get_fd( mqdes, &location ); |
---|
65 | switch ( location ) { |
---|
66 | |
---|
67 | case OBJECTS_LOCAL: |
---|
68 | the_mq = the_mq_fd->Queue; |
---|
69 | |
---|
70 | if ( notification ) { |
---|
71 | if ( _CORE_message_queue_Is_notify_enabled( &the_mq->Message_queue ) ) { |
---|
72 | _Thread_Enable_dispatch(); |
---|
73 | rtems_set_errno_and_return_minus_one( EBUSY ); |
---|
74 | } |
---|
75 | |
---|
76 | _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL, NULL ); |
---|
77 | |
---|
78 | the_mq->notification = *notification; |
---|
79 | |
---|
80 | _CORE_message_queue_Set_notify( |
---|
81 | &the_mq->Message_queue, |
---|
82 | _POSIX_Message_queue_Notify_handler, |
---|
83 | the_mq |
---|
84 | ); |
---|
85 | } else { |
---|
86 | |
---|
87 | _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL, NULL ); |
---|
88 | |
---|
89 | } |
---|
90 | |
---|
91 | _Thread_Enable_dispatch(); |
---|
92 | return 0; |
---|
93 | |
---|
94 | #if defined(RTEMS_MULTIPROCESSING) |
---|
95 | case OBJECTS_REMOTE: |
---|
96 | #endif |
---|
97 | case OBJECTS_ERROR: |
---|
98 | break; |
---|
99 | } |
---|
100 | |
---|
101 | rtems_set_errno_and_return_minus_one( EBADF ); |
---|
102 | } |
---|