source: rtems/c/src/exec/score/src/coremsgseize.c @ 08311cc3

4.104.114.84.95
Last change on this file since 08311cc3 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 *  CORE Message Queue Handler
3 *
4 *  DESCRIPTION:
5 *
6 *  This package is the implementation of the CORE Message Queue Handler.
7 *  This core object provides task synchronization and communication functions
8 *  via messages passed to queue objects.
9 *
10 *  COPYRIGHT (c) 1989-1999.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.OARcorp.com/rtems/license.html.
16 *
17 *  $Id$
18 */
19
20#include <rtems/system.h>
21#include <rtems/score/chain.h>
22#include <rtems/score/isr.h>
23#include <rtems/score/object.h>
24#include <rtems/score/coremsg.h>
25#include <rtems/score/states.h>
26#include <rtems/score/thread.h>
27#include <rtems/score/wkspace.h>
28#if defined(RTEMS_MULTIPROCESSING)
29#include <rtems/score/mpci.h>
30#endif
31
32/*PAGE
33 *
34 *  _CORE_message_queue_Seize
35 *
36 *  This kernel routine dequeues a message, copies the message buffer to
37 *  a given destination buffer, and frees the message buffer to the
38 *  inactive message pool.  The thread will be blocked if wait is TRUE,
39 *  otherwise an error will be given to the thread if no messages are available.
40 *
41 *  Input parameters:
42 *    the_message_queue - pointer to message queue
43 *    id                - id of object we are waitig on
44 *    buffer            - pointer to message buffer to be filled
45 *    size              - pointer to the size of buffer to be filled
46 *    wait              - TRUE if wait is allowed, FALSE otherwise
47 *    timeout           - time to wait for a message
48 *
49 *  Output parameters:  NONE
50 *
51 *  NOTE: Dependent on BUFFER_LENGTH
52 *
53 *  INTERRUPT LATENCY:
54 *    available
55 *    wait
56 */
57
58void _CORE_message_queue_Seize(
59  CORE_message_queue_Control *the_message_queue,
60  Objects_Id                  id,
61  void                       *buffer,
62  unsigned32                 *size,
63  boolean                     wait,
64  Watchdog_Interval           timeout
65)
66{
67  ISR_Level                          level;
68  CORE_message_queue_Buffer_control *the_message;
69  Thread_Control                    *executing;
70
71  executing = _Thread_Executing;
72  executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_SUCCESSFUL;
73  _ISR_Disable( level );
74  if ( the_message_queue->number_of_pending_messages != 0 ) {
75    the_message_queue->number_of_pending_messages -= 1;
76
77    the_message = _CORE_message_queue_Get_pending_message( the_message_queue );
78    _ISR_Enable( level );
79    *size = the_message->Contents.size;
80    _CORE_message_queue_Copy_buffer(the_message->Contents.buffer,buffer,*size );
81    _CORE_message_queue_Free_message_buffer(the_message_queue, the_message );
82    return;
83  }
84
85  if ( !wait ) {
86    _ISR_Enable( level );
87    executing->Wait.return_code = CORE_MESSAGE_QUEUE_STATUS_UNSATISFIED_NOWAIT;
88    return;
89  }
90
91  _Thread_queue_Enter_critical_section( &the_message_queue->Wait_queue );
92  executing->Wait.queue              = &the_message_queue->Wait_queue;
93  executing->Wait.id                 = id;
94  executing->Wait.return_argument    = (void *)buffer;
95  executing->Wait.return_argument_1  = (void *)size;
96  _ISR_Enable( level );
97
98  _Thread_queue_Enqueue( &the_message_queue->Wait_queue, timeout );
99}
100
Note: See TracBrowser for help on using the repository browser.