summaryrefslogtreecommitdiffstats
path: root/cpukit/itron/src/ref_mbf.c
blob: 113870c0d6de6ac110d7aae11feb2a6a2602264f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
 *  ITRON Message Buffer Manager
 *
 *  COPYRIGHT (c) 1989-1999.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.OARcorp.com/rtems/license.html.
 *
 *  $Id$
 */

#if HAVE_CONFIG_H
#include "config.h"
#endif

#include <itron.h>

#include <rtems/itron/msgbuffer.h>
#include <rtems/itron/task.h>

/*
 *  ref_mbf - Reference Message Buffer Status
 */

ER ref_mbf(
  T_RMBF *pk_rmbf,
  ID      mbfid
)
{
  ITRON_Message_buffer_Control      *the_message_buffer;
  Objects_Locations                  location;
  CORE_message_queue_Control        *the_core_msgq;
        
  if ( !pk_rmbf )
    return E_PAR;   /* XXX check this error code */

  the_message_buffer = _ITRON_Message_buffer_Get( mbfid, &location );
  switch ( location ) {   
  case OBJECTS_REMOTE:               /* Multiprocessing not supported */
  case OBJECTS_ERROR:
    return _ITRON_Message_buffer_Clarify_get_id_error( mbfid );
  
  case OBJECTS_LOCAL:
    the_core_msgq = &the_message_buffer->message_queue;

    /*
     *  Fill in the size of message to be sent
     */

    if (the_core_msgq->number_of_pending_messages == 0) {
      pk_rmbf->msgsz = 0;
    } else {
      pk_rmbf->msgsz = ((CORE_message_queue_Buffer_control *)
        the_core_msgq->Pending_messages.first)->Contents.size;
    }
        
    /*
     *  Fill in the size of free buffer
     */

    pk_rmbf->frbufsz =
      (the_core_msgq->maximum_pending_messages - 
       the_core_msgq->number_of_pending_messages) *
       the_core_msgq->maximum_message_size;


    /*
     *  Fill in whether or not there is a waiting task
     */

    if ( !_Thread_queue_First(&the_core_msgq->Wait_queue ) ) 
       pk_rmbf->wtsk = FALSE;
    else
       pk_rmbf->wtsk =  TRUE;

    pk_rmbf->stsk = FALSE;
    _Thread_Enable_dispatch();
    return E_OK;
  }   
  return E_OK;
}