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.org/license/LICENSE. |
---|
15 | */ |
---|
16 | |
---|
17 | #if HAVE_CONFIG_H |
---|
18 | #include "config.h" |
---|
19 | #endif |
---|
20 | |
---|
21 | #include <rtems/posix/mqueueimpl.h> |
---|
22 | |
---|
23 | #include <signal.h> |
---|
24 | |
---|
25 | static void _POSIX_Message_queue_Notify_handler( |
---|
26 | CORE_message_queue_Control *the_message_queue, |
---|
27 | ISR_lock_Context *lock_context |
---|
28 | ) |
---|
29 | { |
---|
30 | POSIX_Message_queue_Control *the_mq; |
---|
31 | int signo; |
---|
32 | |
---|
33 | the_mq = RTEMS_CONTAINER_OF( |
---|
34 | the_message_queue, |
---|
35 | POSIX_Message_queue_Control, |
---|
36 | Message_queue |
---|
37 | ); |
---|
38 | |
---|
39 | signo = the_mq->notification.sigev_signo; |
---|
40 | _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL ); |
---|
41 | _CORE_message_queue_Release( &the_mq->Message_queue, lock_context ); |
---|
42 | |
---|
43 | kill( getpid(), signo ); |
---|
44 | } |
---|
45 | |
---|
46 | int mq_notify( |
---|
47 | mqd_t mqdes, |
---|
48 | const struct sigevent *notification |
---|
49 | ) |
---|
50 | { |
---|
51 | POSIX_Message_queue_Control *the_mq; |
---|
52 | ISR_lock_Context lock_context; |
---|
53 | |
---|
54 | the_mq = _POSIX_Message_queue_Get( mqdes, &lock_context ); |
---|
55 | |
---|
56 | if ( the_mq == NULL ) { |
---|
57 | rtems_set_errno_and_return_minus_one( EBADF ); |
---|
58 | } |
---|
59 | |
---|
60 | _CORE_message_queue_Acquire_critical( |
---|
61 | &the_mq->Message_queue, |
---|
62 | &lock_context |
---|
63 | ); |
---|
64 | |
---|
65 | if ( the_mq->open_count == 0 ) { |
---|
66 | _CORE_message_queue_Release( &the_mq->Message_queue, &lock_context ); |
---|
67 | rtems_set_errno_and_return_minus_one( EBADF ); |
---|
68 | } |
---|
69 | |
---|
70 | if ( notification != NULL ) { |
---|
71 | if ( _CORE_message_queue_Is_notify_enabled( &the_mq->Message_queue ) ) { |
---|
72 | _CORE_message_queue_Release( &the_mq->Message_queue, &lock_context ); |
---|
73 | rtems_set_errno_and_return_minus_one( EBUSY ); |
---|
74 | } |
---|
75 | |
---|
76 | the_mq->notification = *notification; |
---|
77 | |
---|
78 | _CORE_message_queue_Set_notify( |
---|
79 | &the_mq->Message_queue, |
---|
80 | _POSIX_Message_queue_Notify_handler |
---|
81 | ); |
---|
82 | } else { |
---|
83 | _CORE_message_queue_Set_notify( &the_mq->Message_queue, NULL ); |
---|
84 | } |
---|
85 | |
---|
86 | _CORE_message_queue_Release( &the_mq->Message_queue, &lock_context ); |
---|
87 | return 0; |
---|
88 | } |
---|