source: rtems/cpukit/posix/src/mqueuenotify.c @ 0e16fa45

5
Last change on this file since 0e16fa45 was 631b3c8, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/16 at 09:40:18

score: Move thread queue MP callout to context

Drop the multiprocessing (MP) dependent callout parameter from the
thread queue extract, dequeue, flush and unblock methods. Merge this
parameter with the lock context into new structure Thread_queue_Context.
This helps to gets rid of the conditionally compiled method call
helpers.

  • 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  Thread_queue_Context       *queue_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, queue_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  Thread_queue_Context         queue_context;
53
54  the_mq = _POSIX_Message_queue_Get( mqdes, &queue_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    &queue_context
63  );
64
65  if ( the_mq->open_count == 0 ) {
66    _CORE_message_queue_Release( &the_mq->Message_queue, &queue_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, &queue_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, &queue_context );
87  return 0;
88}
Note: See TracBrowser for help on using the repository browser.