1 | /* |
---|
2 | * Thread Handler |
---|
3 | * |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 1989-1999. |
---|
6 | * On-Line Applications Research Corporation (OAR). |
---|
7 | * |
---|
8 | * The license and distribution terms for this file may be |
---|
9 | * found in found in the file LICENSE in this distribution or at |
---|
10 | * http://www.rtems.com/license/LICENSE. |
---|
11 | * |
---|
12 | * $Id$ |
---|
13 | */ |
---|
14 | |
---|
15 | #if HAVE_CONFIG_H |
---|
16 | #include "config.h" |
---|
17 | #endif |
---|
18 | |
---|
19 | #include <rtems/system.h> |
---|
20 | #include <rtems/score/apiext.h> |
---|
21 | #include <rtems/score/context.h> |
---|
22 | #include <rtems/score/interr.h> |
---|
23 | #include <rtems/score/isr.h> |
---|
24 | #include <rtems/score/object.h> |
---|
25 | #include <rtems/score/priority.h> |
---|
26 | #include <rtems/score/states.h> |
---|
27 | #include <rtems/score/sysstate.h> |
---|
28 | #include <rtems/score/thread.h> |
---|
29 | #include <rtems/score/threadq.h> |
---|
30 | |
---|
31 | |
---|
32 | /** |
---|
33 | * This function maps thread IDs to thread control |
---|
34 | * blocks. If ID corresponds to a local thread, then it |
---|
35 | * returns the_thread control pointer which maps to ID |
---|
36 | * and location is set to OBJECTS_LOCAL. If the thread ID is |
---|
37 | * global and resides on a remote node, then location is set |
---|
38 | * to OBJECTS_REMOTE, and the_thread is undefined. |
---|
39 | * Otherwise, location is set to OBJECTS_ERROR and |
---|
40 | * the_thread is undefined. |
---|
41 | * |
---|
42 | * @note The performance of many RTEMS services depends upon |
---|
43 | * the quick execution of the "good object" path in this |
---|
44 | * routine. If there is a possibility of saving a few |
---|
45 | * cycles off the execution time, this routine is worth |
---|
46 | * further optimization attention. |
---|
47 | */ |
---|
48 | |
---|
49 | Thread_Control *_Thread_Get ( |
---|
50 | Objects_Id id, |
---|
51 | Objects_Locations *location |
---|
52 | ) |
---|
53 | { |
---|
54 | uint32_t the_api; |
---|
55 | uint32_t the_class; |
---|
56 | Objects_Information **api_information; |
---|
57 | Objects_Information *information; |
---|
58 | Thread_Control *tp = (Thread_Control *) 0; |
---|
59 | |
---|
60 | if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) { |
---|
61 | _Thread_Disable_dispatch(); |
---|
62 | *location = OBJECTS_LOCAL; |
---|
63 | tp = _Thread_Executing; |
---|
64 | goto done; |
---|
65 | } |
---|
66 | |
---|
67 | the_api = _Objects_Get_API( id ); |
---|
68 | if ( !_Objects_Is_api_valid( the_api ) ) { |
---|
69 | *location = OBJECTS_ERROR; |
---|
70 | goto done; |
---|
71 | } |
---|
72 | |
---|
73 | the_class = _Objects_Get_class( id ); |
---|
74 | if ( the_class != 1 ) { /* threads are always first class :) */ |
---|
75 | *location = OBJECTS_ERROR; |
---|
76 | goto done; |
---|
77 | } |
---|
78 | |
---|
79 | api_information = _Objects_Information_table[ the_api ]; |
---|
80 | if ( !api_information ) { |
---|
81 | *location = OBJECTS_ERROR; |
---|
82 | goto done; |
---|
83 | } |
---|
84 | |
---|
85 | information = api_information[ the_class ]; |
---|
86 | if ( !information ) { |
---|
87 | *location = OBJECTS_ERROR; |
---|
88 | goto done; |
---|
89 | } |
---|
90 | |
---|
91 | tp = (Thread_Control *) _Objects_Get( information, id, location ); |
---|
92 | |
---|
93 | done: |
---|
94 | return tp; |
---|
95 | } |
---|
96 | |
---|