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

Last change on this file since a6eef8b was a6eef8b, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 4, 2003 at 6:52:48 PM

2003-09-04 Joel Sherrill <joel@…>

  • apiext.c, chain.c, coremsg.c, coremsgbroadcast.c, coremsgclose.c, coremsgflush.c, coremsgflushsupp.c, coremsgflushwait.c, coremsginsert.c, coremsgseize.c, coremsgsubmit.c, coremutex.c, coremutexflush.c, coremutexseize.c, coremutexsurrender.c, coresem.c, coresemflush.c, coresemseize.c, coresemsurrender.c, coretod.c, coretodset.c, coretodtickle.c, coretodtoseconds.c, coretodvalidate.c, heap.c, heapallocate.c, heapextend.c, heapfree.c, heapgetinfo.c, heapsizeofuserarea.c, heapwalk.c, interr.c, isr.c, mpci.c, object.c, objectallocate.c, objectallocatebyindex.c, objectclearname.c, objectcomparenameraw.c, objectcomparenamestring.c, objectcopynameraw.c, objectcopynamestring.c, objectextendinformation.c, objectfree.c, objectget.c, objectgetbyindex.c, objectgetisr.c, objectgetnext.c, objectgetnoprotection.c, objectinitializeinformation.c, objectmp.c, objectnametoid.c, objectshrinkinformation.c, thread.c, threadchangepriority.c, threadclearstate.c, threadclose.c, threadcreateidle.c, threaddelayended.c, threaddispatch.c, threadevaluatemode.c, threadget.c, threadhandler.c, threadidlebody.c, threadinitialize.c, threadloadenv.c, threadmp.c, threadq.c, threadqdequeue.c, threadqdequeuefifo.c, threadqdequeuepriority.c, threadqenqueue.c, threadqenqueuefifo.c, threadqenqueuepriority.c, threadqextract.c, threadqextractfifo.c, threadqextractpriority.c, threadqextractwithproxy.c, threadqfirst.c, threadqfirstfifo.c, threadqfirstpriority.c, threadqflush.c, threadqtimeout.c, threadready.c, threadreset.c, threadresettimeslice.c, threadrestart.c, threadresume.c, threadrotatequeue.c, threadsetpriority.c, threadsetstate.c, threadsettransient.c, threadstackallocate.c, threadstackfree.c, threadstart.c, threadstartmultitasking.c, threadsuspend.c, threadtickletimeslice.c, threadyieldprocessor.c, userext.c, watchdog.c, watchdogadjust.c, watchdoginsert.c, watchdogremove.c, watchdogtickle.c, wkspace.c: URL for license changed.
  • Property mode set to 100644
File size: 3.2 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.rtems.com/license/LICENSE.
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 *
46 *  Output parameters:
47 *    TRUE   - if the message queue is initialized
48 *    FALSE  - if the message queue is NOT initialized
49 */
50
51boolean _CORE_message_queue_Initialize(
52  CORE_message_queue_Control    *the_message_queue,
53  CORE_message_queue_Attributes *the_message_queue_attributes,
54  unsigned32                     maximum_pending_messages,
55  unsigned32                     maximum_message_size
56)
57{
58  unsigned32 message_buffering_required;
59  unsigned32 allocated_message_size;
60
61  the_message_queue->maximum_pending_messages   = maximum_pending_messages;
62  the_message_queue->number_of_pending_messages = 0;
63  the_message_queue->maximum_message_size       = maximum_message_size;
64  _CORE_message_queue_Set_notify( the_message_queue, NULL, NULL );
65 
66  /*
67   * round size up to multiple of a ptr for chain init
68   */
69 
70  allocated_message_size = maximum_message_size;
71  if (allocated_message_size & (sizeof(unsigned32) - 1)) {
72      allocated_message_size += sizeof(unsigned32);
73      allocated_message_size &= ~(sizeof(unsigned32) - 1);
74  }
75   
76  message_buffering_required = maximum_pending_messages *
77       (allocated_message_size + sizeof(CORE_message_queue_Buffer_control));
78 
79  the_message_queue->message_buffers = (CORE_message_queue_Buffer *) 
80     _Workspace_Allocate( message_buffering_required );
81 
82  if (the_message_queue->message_buffers == 0)
83    return FALSE;
84 
85  _Chain_Initialize (
86    &the_message_queue->Inactive_messages,
87    the_message_queue->message_buffers,
88    maximum_pending_messages,
89    allocated_message_size + sizeof( CORE_message_queue_Buffer_control )
90  );
91 
92  _Chain_Initialize_empty( &the_message_queue->Pending_messages );
93 
94  _Thread_queue_Initialize(
95    &the_message_queue->Wait_queue,
96    _CORE_message_queue_Is_priority( the_message_queue_attributes ) ?
97       THREAD_QUEUE_DISCIPLINE_PRIORITY : THREAD_QUEUE_DISCIPLINE_FIFO,
98    STATES_WAITING_FOR_MESSAGE,
99    CORE_MESSAGE_QUEUE_STATUS_TIMEOUT
100  );
101
102  return TRUE;
103}
Note: See TracBrowser for help on using the repository browser.