source: rtems/cpukit/score/src/coremsg.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.4 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_Initialize
35 *
36 *  This routine initializes a newly created message queue based on the
37 *  specified data.
38 *
39 *  Input parameters:
40 *    the_message_queue            - the message queue to initialize
41 *    the_class                    - the API specific object class
42 *    the_message_queue_attributes - the message queue's attributes
43 *    maximum_pending_messages     - maximum message and reserved buffer count
44 *    maximum_message_size         - maximum size of each message
45 *    proxy_extract_callout        - remote extract support
46 *
47 *  Output parameters:
48 *    TRUE   - if the message queue is initialized
49 *    FALSE  - if the message queue is NOT initialized
50 */
51
52boolean _CORE_message_queue_Initialize(
53  CORE_message_queue_Control    *the_message_queue,
54  Objects_Classes                the_class,
55  CORE_message_queue_Attributes *the_message_queue_attributes,
56  unsigned32                     maximum_pending_messages,
57  unsigned32                     maximum_message_size,
58  Thread_queue_Extract_callout   proxy_extract_callout
59)
60{
61  unsigned32 message_buffering_required;
62  unsigned32 allocated_message_size;
63
64  the_message_queue->maximum_pending_messages   = maximum_pending_messages;
65  the_message_queue->number_of_pending_messages = 0;
66  the_message_queue->maximum_message_size       = maximum_message_size;
67  _CORE_message_queue_Set_notify( the_message_queue, NULL, NULL );
68 
69  /*
70   * round size up to multiple of a ptr for chain init
71   */
72 
73  allocated_message_size = maximum_message_size;
74  if (allocated_message_size & (sizeof(unsigned32) - 1)) {
75      allocated_message_size += sizeof(unsigned32);
76      allocated_message_size &= ~(sizeof(unsigned32) - 1);
77  }
78   
79  message_buffering_required = maximum_pending_messages *
80       (allocated_message_size + sizeof(CORE_message_queue_Buffer_control));
81 
82  the_message_queue->message_buffers = (CORE_message_queue_Buffer *)
83     _Workspace_Allocate( message_buffering_required );
84 
85  if (the_message_queue->message_buffers == 0)
86    return FALSE;
87 
88  _Chain_Initialize (
89    &the_message_queue->Inactive_messages,
90    the_message_queue->message_buffers,
91    maximum_pending_messages,
92    allocated_message_size + sizeof( CORE_message_queue_Buffer_control )
93  );
94 
95  _Chain_Initialize_empty( &the_message_queue->Pending_messages );
96 
97  _Thread_queue_Initialize(
98    &the_message_queue->Wait_queue,
99    the_class,
100    _CORE_message_queue_Is_priority( the_message_queue_attributes ) ?
101       THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO,
102    STATES_WAITING_FOR_MESSAGE,
103    proxy_extract_callout,
104    CORE_MESSAGE_QUEUE_STATUS_TIMEOUT
105  );
106
107  return TRUE;
108}
Note: See TracBrowser for help on using the repository browser.