source: rtems/cpukit/posix/src/mqueuenotify.c @ c8982e5

5
Last change on this file since c8982e5 was c8982e5, checked in by Sebastian Huber <sebastian.huber@…>, on 04/26/16 at 19:20:31

posix: Simplify message queues

The mq_open() function returns a descriptor to a POSIX message queue
object identified by a name. This is similar to sem_open(). In
contrast to the POSIX semaphore the POSIX message queues use a separate
object for the descriptor. This extra object is superfluous, since the
object identifier can be used directly for this purpose, just like for
the semaphores.

Update #2702.
Update #2555.

  • Property mode set to 100644
File size: 2.1 KB
Line 
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
25static 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
46int 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}
Note: See TracBrowser for help on using the repository browser.