summaryrefslogtreecommitdiffstats
path: root/c/src/exec/score/macros/rtems/score/userext.inl
blob: 3904bd1657e06acee9874f83488da133405d0cdc (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
160
161
162
163
164
165
166
167
168
169
170
/*  userext.inl
 *
 *  This file contains the macro implementation of the inlined routines
 *  from the User Extension Handler
 *
 *  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$
 */

#ifndef __USER_EXTENSIONS_inl
#define __USER_EXTENSIONS_inl

/*PAGE
 *
 *  _User_extensions_Handler_initialization
 *
 */

#define _User_extensions_Handler_initialization( \
  _number_of_extensions, _initial_extensions \
) \
  { \
    User_extensions_Control *extension; \
    unsigned32               i; \
    \
    _Chain_Initialize_empty( &_User_extensions_List ); \
    _Chain_Initialize_empty( &_User_extensions_Switches_list ); \
    \
    if ( (_initial_extensions) ) { \
      extension = _Workspace_Allocate_or_fatal_error( \
          sizeof(User_extensions_Control) * _number_of_extensions ); \
      \
      memset ( \
        extension, \
        0, \
        _number_of_extensions * sizeof( User_extensions_Control ) \
      ); \
      \
      for ( i = 0 ; i < _number_of_extensions ; i++ ) { \
        _User_extensions_Add_set (extension, &_initial_extensions[i]); \
        extension++; \
      } \
    } \
  }

/*PAGE
 *
 *  _User_extensions_Add_set
 */

#define _User_extensions_Add_set( _the_extension, _extension_table ) \
  do { \
    (_the_extension)->Callouts = *(_extension_table); \
    \
    _Chain_Prepend( &_User_extensions_List, &(_the_extension)->Node ); \
    \
    if ( (_the_extension)->Callouts.thread_switch != NULL ) { \
      (_the_extension)->Switch.thread_switch = \
        (_the_extension)->Callouts.thread_switch; \
      _Chain_Append( \
        &_User_extensions_Switches_list, \
        &(_the_extension)->Switch.Node \
     ); \
    } \
  } while ( 0 )
 

/*PAGE
 *
 *  _User_extensions_Add_API_set
 */
 
#define _User_extensions_Add_API_set( _the_extension ) \
  do { \
    _Chain_Prepend( &_User_extensions_List, &(_the_extension)->Node ); \
    \
    if ( (_the_extension)->Callouts.thread_switch != NULL ) { \
      (_the_extension)->Switch.thread_switch = \
          (_the_extension)->Callouts.thread_switch; \
      _Chain_Append( \
        &_User_extensions_Switches_list, &(_the_extension)->Switch.Node ); \
    } \
  } while ( 0 )
 
 
/*PAGE
 *
 *  _User_extensions_Remove_set
 */

#define _User_extensions_Remove_set( _the_extension ) \
  do { \
    _Chain_Extract( &(_the_extension)->Node ); \
    \
    if ( (_the_extension)->Callouts.thread_switch != NULL ) { \
      _Chain_Extract( &(_the_extension)->Node ); \
    } \
  } while (0)

/*PAGE
 *
 *  _User_extensions_Run_list_forward
 *
 *  NOTE:  No parentheses around macro names here to avoid
 *         messing up the name and function call expansion.
 */

#define _User_extensions_Run_list_forward( _list, _name, _arguments ) \
  do { \
    Chain_Node              *the_node; \
    User_extensions_Control *the_extension; \
    \
    for ( the_node = (_list).first ; \
          !_Chain_Is_tail( &(_list), the_node ) ; \
          the_node = the_node->next ) { \
      the_extension = (User_extensions_Control *) the_node; \
      \
      if ( the_extension->Callouts.## _name != NULL ) \
        (*the_extension->Callouts.## _name) _arguments; \
      \
    } \
    \
  } while ( 0 )

/*PAGE
 *
 *  _User_extensions_Run_list_backward
 *
 *  NOTE:  No parentheses around macro names here to avoid
 *         messing up the name and function call expansion.
 */

#define _User_extensions_Run_list_backward( _list, _name, _arguments ) \
  do { \
    Chain_Node              *the_node; \
    User_extensions_Control *the_extension; \
    \
    for ( the_node = (_list).last ; \
          !_Chain_Is_head( &(_list), the_node ) ; \
          the_node = the_node->previous ) { \
      the_extension = (User_extensions_Control *) the_node; \
      \
      if ( the_extension->Callouts.## _name != NULL ) \
        (*the_extension->Callouts.## _name) _arguments; \
      \
    } \
    \
  } while ( 0 )

/*PAGE
 *
 *  _User_extensions_Thread_switch
 *
 */

#define _User_extensions_Thread_switch( _executing, _heir ) \
  _User_extensions_Run_list_forward( \
    _User_extensions_Switches_list, \
    thread_switch, \
    (_executing, _heir) \
  )

#endif
/* end of include file */