summaryrefslogtreecommitdiffstats
path: root/cpukit/rtems/src/mp.c
blob: a6b6dad8ba8521bbfb436651945d34d60b4fda68 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*
 *  Multiprocessing Manager
 *
 *
 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
 *  On-Line Applications Research Corporation (OAR).
 *  All rights assigned to U.S. Government, 1994.
 *
 *  This material may be reproduced by or for the U.S. Government pursuant
 *  to the copyright license under the clause at DFARS 252.227-7013.  This
 *  notice must appear in all copies of this file and its derivatives.
 *
 *  $Id$
 */

#include <rtems/system.h>
#include <rtems/config.h>
#include <rtems/cpu.h>
#include <rtems/event.h>
#include <rtems/fatal.h>
#include <rtems/intthrd.h>
#include <rtems/message.h>
#include <rtems/mp.h>
#include <rtems/mpci.h>
#include <rtems/mppkt.h>
#include <rtems/part.h>
#include <rtems/sem.h>
#include <rtems/signal.h>
#include <rtems/states.h>
#include <rtems/tasks.h>
#include <rtems/thread.h>
#include <rtems/threadq.h>
#include <rtems/watchdog.h>

/*PAGE
 *
 *  _Multiprocessing_Manager_initialization
 *
 */

void _Multiprocessing_Manager_initialization ( void )
{
  if ( _Configuration_MP_table->node < 1 ||
       _Configuration_MP_table->node > _Configuration_MP_table->maximum_nodes )
     rtems_fatal_error_occurred( RTEMS_INVALID_NODE );

  _Internal_threads_Set_MP_receive_server( _Multiprocessing_Receive_server );
}

/*PAGE
 *
 *  rtems_multiprocessing_announce
 *
 */

void rtems_multiprocessing_announce ( void )
{
  _Thread_Disable_dispatch();
  _Event_sets_Post(
    RTEMS_EVENT_0,
    &_Internal_threads_System_initialization_thread->pending_events
  );
  _Event_Surrender( _Internal_threads_System_initialization_thread );
  _Thread_Enable_dispatch();
}

/*PAGE
 *
 *  _Multiprocessing_Receive_server
 *
 */

typedef void (*packet_processor)( rtems_packet_prefix * );

packet_processor _Multiprocessor_Packet_processors[] = {
  _Internal_threads_MP_Process_packet, /* RTEMS_MP_PACKET_INTERNAL_THREADS */
  _RTEMS_tasks_MP_Process_packet,      /* RTEMS_MP_PACKET_TASKS */
  _Message_queue_MP_Process_packet,    /* RTEMS_MP_PACKET_MESSAGE_QUEUE */
  _Semaphore_MP_Process_packet,        /* RTEMS_MP_PACKET_SEMAPHORE */
  _Partition_MP_Process_packet,        /* RTEMS_MP_PACKET_PARTITION */
  0,                                   /* RTEMS_MP_PACKET_REGION */
  _Event_MP_Process_packet,            /* RTEMS_MP_PACKET_EVENT */
  _Signal_MP_Process_packet            /* RTEMS_MP_PACKET_SIGNAL */
};

Thread _Multiprocessing_Receive_server (
  Thread_Argument ignored
)
{

  rtems_packet_prefix *the_packet;
  packet_processor     the_function;

  for ( ; ; ) {

    _Thread_Disable_dispatch();
    _Event_Seize( RTEMS_EVENT_0, RTEMS_DEFAULT_OPTIONS, RTEMS_NO_TIMEOUT );
    _Thread_Enable_dispatch();

    for ( ; ; ) {
      the_packet = _MPCI_Receive_packet();

      if ( !the_packet ) 
        break;

      _Thread_Executing->receive_packet = the_packet;

      if ( !_Mp_packet_Is_valid_packet_class ( the_packet->the_class ) )
        break;

      the_function = _Multiprocessor_Packet_processors[ the_packet->the_class ];
    
      if ( !the_function )
        break;

      (*the_function)( the_packet );
#if 0
      switch ( the_packet->the_class ) {
 
        case RTEMS_MP_PACKET_INTERNAL_THREADS:
          _Internal_threads_MP_Process_packet( the_packet );
          break;
 
        case RTEMS_MP_PACKET_TASKS:
          _RTEMS_tasks_MP_Process_packet( the_packet );
          break;
 
        case RTEMS_MP_PACKET_MESSAGE_QUEUE:
          _Message_queue_MP_Process_packet( the_packet );
          break;
 
        case RTEMS_MP_PACKET_SEMAPHORE:
          _Semaphore_MP_Process_packet( the_packet );
          break;
 
        case RTEMS_MP_PACKET_PARTITION:
          _Partition_MP_Process_packet( the_packet );
          break;
 
        case RTEMS_MP_PACKET_REGION:
          /* Global regions are unsupported at this time */
          break;
 
        case RTEMS_MP_PACKET_EVENT:
          _Event_MP_Process_packet( the_packet );
          break;
 
        case RTEMS_MP_PACKET_SIGNAL:
          _Signal_MP_Process_packet( the_packet );
          break;
      }
#endif


    }
  }
}

/* end of file */