source: rtems/c/src/exec/score/inline/rtems/score/thread.inl @ 0df8293e

4.104.114.84.95
Last change on this file since 0df8293e was 0df8293e, checked in by Joel Sherrill <joel.sherrill@…>, on 05/15/02 at 15:14:58

2002-05-15 Chris Johns <ccj@…>

  • include/rtems/score/thread.h, inline/rtems/score/thread.inl, src/threaddispatch.c, src/threadinitialize.c: Move the C library re-enterrant support directly into the thread dispatch code. RTEMS needs libc and so requiring libc to use a user extension with its overhead is not the best solution. This patch lowers the overhead to 2 pointer moves.
  • Property mode set to 100644
File size: 8.3 KB
Line 
1/*  thread.inl
2 *
3 *  This file contains the macro implementation of the inlined
4 *  routines from the Thread handler.
5 *
6 *  COPYRIGHT (c) 1989-1999.
7 *  On-Line Applications Research Corporation (OAR).
8 *
9 *  The license and distribution terms for this file may be
10 *  found in the file LICENSE in this distribution or at
11 *  http://www.OARcorp.com/rtems/license.html.
12 *
13 *  $Id$
14 */
15
16#ifndef __THREAD_inl
17#define __THREAD_inl
18
19/*PAGE
20 *
21 *  _Thread_Stop_multitasking
22 *
23 *  DESCRIPTION:
24 *
25 *  This routine halts multitasking and returns control to
26 *  the "thread" (i.e. the BSP) which initially invoked the
27 *  routine which initialized the system.
28 */
29
30RTEMS_INLINE_ROUTINE void _Thread_Stop_multitasking( void )
31{
32  _Context_Switch( &_Thread_Executing->Registers, &_Thread_BSP_context );
33}
34
35/*PAGE
36 *
37 *  _Thread_Is_executing
38 *
39 *  DESCRIPTION:
40 *
41 *  This function returns TRUE if the_thread is the currently executing
42 *  thread, and FALSE otherwise.
43 */
44
45RTEMS_INLINE_ROUTINE boolean _Thread_Is_executing (
46  Thread_Control *the_thread
47)
48{
49  return ( the_thread == _Thread_Executing );
50}
51
52/*PAGE
53 *
54 *  _Thread_Is_heir
55 *
56 *  DESCRIPTION:
57 *
58 *  This function returns TRUE if the_thread is the heir
59 *  thread, and FALSE otherwise.
60 */
61
62RTEMS_INLINE_ROUTINE boolean _Thread_Is_heir (
63  Thread_Control *the_thread
64)
65{
66  return ( the_thread == _Thread_Heir );
67}
68
69/*PAGE
70 *
71 *  _Thread_Is_executing_also_the_heir
72 *
73 *  DESCRIPTION:
74 *
75 *  This function returns TRUE if the currently executing thread
76 *  is also the heir thread, and FALSE otherwise.
77 */
78
79RTEMS_INLINE_ROUTINE boolean _Thread_Is_executing_also_the_heir( void )
80{
81  return ( _Thread_Executing == _Thread_Heir );
82}
83
84/*PAGE
85 *
86 *  _Thread_Unblock
87 *
88 *  DESCRIPTION:
89 *
90 *  This routine clears any blocking state for the_thread.  It performs
91 *  any necessary scheduling operations including the selection of
92 *  a new heir thread.
93 */
94
95RTEMS_INLINE_ROUTINE void _Thread_Unblock (
96  Thread_Control *the_thread
97)
98{
99  _Thread_Clear_state( the_thread, STATES_BLOCKED );
100}
101
102/*PAGE
103 *
104 *  _Thread_Restart_self
105 *
106 *  DESCRIPTION:
107 *
108 *  This routine resets the current context of the calling thread
109 *  to that of its initial state.
110 */
111
112RTEMS_INLINE_ROUTINE void _Thread_Restart_self( void )
113{
114#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
115  if ( _Thread_Executing->fp_context != NULL )
116    _Context_Restore_fp( &_Thread_Executing->fp_context );
117#endif
118
119  _CPU_Context_Restart_self( &_Thread_Executing->Registers );
120}
121
122/*PAGE
123 *
124 *  _Thread_Calculate_heir
125 *
126 *  DESCRIPTION:
127 *
128 *  This function returns a pointer to the highest priority
129 *  ready thread.
130 */
131
132RTEMS_INLINE_ROUTINE void _Thread_Calculate_heir( void )
133{
134  _Thread_Heir = (Thread_Control *)
135    _Thread_Ready_chain[ _Priority_Get_highest() ].first;
136}
137
138/*PAGE
139 *
140 *  _Thread_Is_allocated_fp
141 *
142 *  DESCRIPTION:
143 *
144 *  This function returns TRUE if the floating point context of
145 *  the_thread is currently loaded in the floating point unit, and
146 *  FALSE otherwise.
147 */
148
149#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
150RTEMS_INLINE_ROUTINE boolean _Thread_Is_allocated_fp (
151  Thread_Control *the_thread
152)
153{
154  return ( the_thread == _Thread_Allocated_fp );
155}
156#endif
157
158/*PAGE
159 *
160 *  _Thread_Deallocate_fp
161 *
162 *  DESCRIPTION:
163 *
164 *  This routine is invoked when the currently loaded floating
165 *  point context is now longer associated with an active thread.
166 */
167
168#if ( CPU_HARDWARE_FP == TRUE ) || ( CPU_SOFTWARE_FP == TRUE )
169RTEMS_INLINE_ROUTINE void _Thread_Deallocate_fp( void )
170{
171  _Thread_Allocated_fp = NULL;
172}
173#endif
174
175/*PAGE
176 *
177 *  _Thread_Disable_dispatch
178 *
179 *  DESCRIPTION:
180 *
181 *  This routine prevents dispatching.
182 */
183
184RTEMS_INLINE_ROUTINE void _Thread_Disable_dispatch( void )
185{
186  _Thread_Dispatch_disable_level += 1;
187}
188
189/*PAGE
190 *
191 *  _Thread_Enable_dispatch
192 *
193 *  DESCRIPTION:
194 *
195 *  This routine allows dispatching to occur again.  If this is
196 *  the outer most dispatching critical section, then a dispatching
197 *  operation will be performed and, if necessary, control of the
198 *  processor will be transferred to the heir thread.
199 */
200
201#if ( CPU_INLINE_ENABLE_DISPATCH == TRUE )
202RTEMS_INLINE_ROUTINE void _Thread_Enable_dispatch()
203{
204  if ( (--_Thread_Dispatch_disable_level) == 0 )
205    _Thread_Dispatch();
206}
207#endif
208
209#if ( CPU_INLINE_ENABLE_DISPATCH == FALSE )
210void _Thread_Enable_dispatch( void );
211#endif
212
213/*PAGE
214 *
215 *  _Thread_Unnest_dispatch
216 *
217 *  DESCRIPTION:
218 *
219 *  This routine allows dispatching to occur again.  However,
220 *  no dispatching operation is performed even if this is the outer
221 *  most dispatching critical section.
222 */
223
224RTEMS_INLINE_ROUTINE void _Thread_Unnest_dispatch( void )
225{
226  _Thread_Dispatch_disable_level -= 1;
227}
228
229/*PAGE
230 *
231 *  _Thread_Is_dispatching_enabled
232 *
233 *  DESCRIPTION:
234 *
235 *  This function returns TRUE if dispatching is disabled, and FALSE
236 *  otherwise.
237 */
238
239RTEMS_INLINE_ROUTINE boolean _Thread_Is_dispatching_enabled( void )
240{
241  return ( _Thread_Dispatch_disable_level == 0 );
242}
243
244/*PAGE
245 *
246 *  _Thread_Is_context_switch_necessary
247 *
248 *  DESCRIPTION:
249 *
250 *  This function returns TRUE if dispatching is disabled, and FALSE
251 *  otherwise.
252 */
253
254RTEMS_INLINE_ROUTINE boolean _Thread_Is_context_switch_necessary( void )
255{
256  return ( _Context_Switch_necessary );
257}
258
259/*PAGE
260 *
261 *  _Thread_Dispatch_initialization
262 *
263 *  DESCRIPTION:
264 *
265 *  This routine initializes the thread dispatching subsystem.
266 */
267
268RTEMS_INLINE_ROUTINE void _Thread_Dispatch_initialization( void )
269{
270  _Thread_Dispatch_disable_level = 1;
271}
272
273/*PAGE
274 *
275 *  _Thread_Is_null
276 *
277 *  DESCRIPTION:
278 *
279 *  This function returns TRUE if the_thread is NULL and FALSE otherwise.
280 */
281
282RTEMS_INLINE_ROUTINE boolean _Thread_Is_null (
283  Thread_Control *the_thread
284)
285{
286  return ( the_thread == NULL );
287}
288
289/*PAGE
290 *
291 *  _Thread_Get
292 *
293 *  DESCRIPTION:
294 *
295 *  This function maps thread IDs to thread control
296 *  blocks.  If ID corresponds to a local thread, then it
297 *  returns the_thread control pointer which maps to ID
298 *  and location is set to OBJECTS_LOCAL.  If the thread ID is
299 *  global and resides on a remote node, then location is set
300 *  to OBJECTS_REMOTE, and the_thread is undefined.
301 *  Otherwise, location is set to OBJECTS_ERROR and
302 *  the_thread is undefined.
303 *
304 *  NOTE:  XXX... This routine may be able to be optimized.
305 */
306
307RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Get (
308  Objects_Id         id,
309  Objects_Locations *location
310)
311{
312  Objects_Classes      the_class;
313  Objects_Information *information;
314  Thread_Control      *tp = (Thread_Control *) 0;
315 
316  if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) {
317    _Thread_Disable_dispatch();
318    *location = OBJECTS_LOCAL;
319    tp = _Thread_Executing;
320    goto done;
321  }
322 
323  the_class = _Objects_Get_class( id );
324 
325  if ( the_class > OBJECTS_CLASSES_LAST ) {
326    *location = OBJECTS_ERROR;
327    goto done;
328  }
329 
330  information = _Objects_Information_table[ the_class ];
331 
332  if ( !information || !information->is_thread ) {
333    *location = OBJECTS_ERROR;
334    goto done;
335  }
336 
337  tp = (Thread_Control *) _Objects_Get( information, id, location );
338 
339done:
340  return tp;
341}
342
343
344/*
345 *  _Thread_Is_proxy_blocking
346 *
347 *  DESCRIPTION:
348 *
349 *  This function returns TRUE if the status code is equal to the
350 *  status which indicates that a proxy is blocking, and FALSE otherwise.
351 */
352
353RTEMS_INLINE_ROUTINE boolean _Thread_Is_proxy_blocking (
354  unsigned32 code
355)
356{
357  return (code == THREAD_STATUS_PROXY_BLOCKING);
358}
359
360/*PAGE
361 *
362 *  _Thread_Internal_allocate
363 *
364 *  DESCRIPTION:
365 *
366 *  This routine allocates an internal thread.
367 */
368 
369RTEMS_INLINE_ROUTINE Thread_Control *_Thread_Internal_allocate( void )
370{
371  return (Thread_Control *) _Objects_Allocate( &_Thread_Internal_information );
372}
373 
374/*PAGE
375 *
376 *  _Thread_Internal_free
377 *
378 *  DESCRIPTION:
379 *
380 *  This routine frees an internal thread.
381 */
382 
383RTEMS_INLINE_ROUTINE void _Thread_Internal_free (
384  Thread_Control *the_task
385)
386{
387  _Objects_Free( &_Thread_Internal_information, &the_task->Object );
388}
389
390/*PAGE
391 *
392 *  _Thread_Get_libc_reent
393 *
394 *  DESCRIPTION:
395 *
396 *  This routine returns the C library re-enterant pointer.
397 */
398 
399RTEMS_INLINE_ROUTINE void **_Thread_Get_libc_reent( void )
400{
401  return _Thread_libc_reent;
402}
403
404/*PAGE
405 *
406 *  _Thread_Set_libc_reent
407 *
408 *  DESCRIPTION:
409 *
410 *  This routine set the C library re-enterant pointer.
411 */
412 
413RTEMS_INLINE_ROUTINE void _Thread_Set_libc_reent (
414  void **libc_reent
415)
416{
417  _Thread_libc_reent = libc_reent;
418}
419
420#endif
421/* end of include file */
Note: See TracBrowser for help on using the repository browser.