source: rtems/cpukit/score/src/coremsg.c @ aae7f1a1

4.104.115
Last change on this file since aae7f1a1 was aae7f1a1, checked in by Ralf Corsepius <ralf.corsepius@…>, on 12/22/08 at 05:52:32

Eliminate TRUE/FALSE.

  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[3652ad35]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 *
[08311cc3]10 *  COPYRIGHT (c) 1989-1999.
[3652ad35]11 *  On-Line Applications Research Corporation (OAR).
12 *
[98e4ebf5]13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
[dd687d97]15 *  http://www.rtems.com/license/LICENSE.
[3652ad35]16 *
17 *  $Id$
18 */
19
[a8eed23]20#if HAVE_CONFIG_H
21#include "config.h"
22#endif
23
[3652ad35]24#include <rtems/system.h>
[5e9b32b]25#include <rtems/score/chain.h>
26#include <rtems/score/isr.h>
27#include <rtems/score/object.h>
28#include <rtems/score/coremsg.h>
29#include <rtems/score/states.h>
30#include <rtems/score/thread.h>
31#include <rtems/score/wkspace.h>
[3652ad35]32
33/*PAGE
34 *
35 *  _CORE_message_queue_Initialize
36 *
37 *  This routine initializes a newly created message queue based on the
38 *  specified data.
39 *
40 *  Input parameters:
41 *    the_message_queue            - the message queue to initialize
42 *    the_class                    - the API specific object class
43 *    the_message_queue_attributes - the message queue's attributes
44 *    maximum_pending_messages     - maximum message and reserved buffer count
45 *    maximum_message_size         - maximum size of each message
46 *
47 *  Output parameters:
[aae7f1a1]48 *    true   - if the message queue is initialized
49 *    false  - if the message queue is NOT initialized
[3652ad35]50 */
51
[484a769]52bool _CORE_message_queue_Initialize(
[3652ad35]53  CORE_message_queue_Control    *the_message_queue,
54  CORE_message_queue_Attributes *the_message_queue_attributes,
[c1a886be]55  uint32_t                       maximum_pending_messages,
[f773c012]56  size_t                         maximum_message_size
[3652ad35]57)
58{
[f773c012]59  size_t message_buffering_required;
60  size_t allocated_message_size;
[3652ad35]61
62  the_message_queue->maximum_pending_messages   = maximum_pending_messages;
63  the_message_queue->number_of_pending_messages = 0;
64  the_message_queue->maximum_message_size       = maximum_message_size;
[5e9b32b]65  _CORE_message_queue_Set_notify( the_message_queue, NULL, NULL );
[9b63fbf8]66 
[3652ad35]67  /*
[9b63fbf8]68   *  Round size up to multiple of a pointer for chain init and
69   *  check for overflow on adding overhead to each message.
[3652ad35]70   */
[9b63fbf8]71 
[3652ad35]72  allocated_message_size = maximum_message_size;
[9929e2d]73  if (allocated_message_size & (sizeof(uint32_t) - 1)) {
74      allocated_message_size += sizeof(uint32_t);
75      allocated_message_size &= ~(sizeof(uint32_t) - 1);
[3652ad35]76  }
[9b63fbf8]77   
78  if (allocated_message_size < maximum_message_size)
[484a769]79    return false;
[05279b84]80
[9b63fbf8]81  /*
82   *  Calculate how much total memory is required for message buffering and
83   *  check for overflow on the multiplication.
84   */
[f773c012]85  message_buffering_required = (size_t) maximum_pending_messages *
[3652ad35]86       (allocated_message_size + sizeof(CORE_message_queue_Buffer_control));
[9b63fbf8]87 
88  if (message_buffering_required < allocated_message_size)
[484a769]89    return false;
[05279b84]90
[9b63fbf8]91  /*
92   *  Attempt to allocate the message memory
93   */
94  the_message_queue->message_buffers = (CORE_message_queue_Buffer *)
[3652ad35]95     _Workspace_Allocate( message_buffering_required );
[9b63fbf8]96 
[3652ad35]97  if (the_message_queue->message_buffers == 0)
[484a769]98    return false;
[9b63fbf8]99 
100  /*
101   *  Initialize the pool of inactive messages, pending messages,
102   *  and set of waiting threads.
103   */
[3652ad35]104  _Chain_Initialize (
105    &the_message_queue->Inactive_messages,
106    the_message_queue->message_buffers,
[f773c012]107    (size_t) maximum_pending_messages,
[3652ad35]108    allocated_message_size + sizeof( CORE_message_queue_Buffer_control )
109  );
[9b63fbf8]110 
[3652ad35]111  _Chain_Initialize_empty( &the_message_queue->Pending_messages );
[9b63fbf8]112 
[3652ad35]113  _Thread_queue_Initialize(
114    &the_message_queue->Wait_queue,
115    _CORE_message_queue_Is_priority( the_message_queue_attributes ) ?
116       THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO,
117    STATES_WAITING_FOR_MESSAGE,
118    CORE_MESSAGE_QUEUE_STATUS_TIMEOUT
119  );
120
[484a769]121  return true;
[3652ad35]122}
Note: See TracBrowser for help on using the repository browser.