1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Maps Thread IDs to TCB Pointer |
---|
5 | * |
---|
6 | * @ingroup ScoreThread |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2011. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.com/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #if HAVE_CONFIG_H |
---|
19 | #include "config.h" |
---|
20 | #endif |
---|
21 | |
---|
22 | #include <rtems/system.h> |
---|
23 | #include <rtems/score/apiext.h> |
---|
24 | #include <rtems/score/context.h> |
---|
25 | #include <rtems/score/interr.h> |
---|
26 | #include <rtems/score/isr.h> |
---|
27 | #include <rtems/score/object.h> |
---|
28 | #include <rtems/score/priority.h> |
---|
29 | #include <rtems/score/states.h> |
---|
30 | #include <rtems/score/sysstate.h> |
---|
31 | #include <rtems/score/thread.h> |
---|
32 | #include <rtems/score/threaddispatch.h> |
---|
33 | #include <rtems/score/threadq.h> |
---|
34 | |
---|
35 | Thread_Control *_Thread_Get ( |
---|
36 | Objects_Id id, |
---|
37 | Objects_Locations *location |
---|
38 | ) |
---|
39 | { |
---|
40 | uint32_t the_api; |
---|
41 | uint32_t the_class; |
---|
42 | Objects_Information **api_information; |
---|
43 | Objects_Information *information; |
---|
44 | Thread_Control *tp = (Thread_Control *) 0; |
---|
45 | |
---|
46 | if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) { |
---|
47 | _Thread_Disable_dispatch(); |
---|
48 | *location = OBJECTS_LOCAL; |
---|
49 | tp = _Thread_Executing; |
---|
50 | goto done; |
---|
51 | } |
---|
52 | |
---|
53 | the_api = _Objects_Get_API( id ); |
---|
54 | if ( !_Objects_Is_api_valid( the_api ) ) { |
---|
55 | *location = OBJECTS_ERROR; |
---|
56 | goto done; |
---|
57 | } |
---|
58 | |
---|
59 | the_class = _Objects_Get_class( id ); |
---|
60 | if ( the_class != 1 ) { /* threads are always first class :) */ |
---|
61 | *location = OBJECTS_ERROR; |
---|
62 | goto done; |
---|
63 | } |
---|
64 | |
---|
65 | api_information = _Objects_Information_table[ the_api ]; |
---|
66 | /* |
---|
67 | * There is no way for this to happen if POSIX is enabled. But there |
---|
68 | * is actually a test case in sp43 for this which trips it whether or |
---|
69 | * not POSIX is enabled. So in the interest of safety, this is left |
---|
70 | * on in all configurations. |
---|
71 | */ |
---|
72 | if ( !api_information ) { |
---|
73 | *location = OBJECTS_ERROR; |
---|
74 | goto done; |
---|
75 | } |
---|
76 | |
---|
77 | information = api_information[ the_class ]; |
---|
78 | if ( !information ) { |
---|
79 | *location = OBJECTS_ERROR; |
---|
80 | goto done; |
---|
81 | } |
---|
82 | |
---|
83 | tp = (Thread_Control *) _Objects_Get( information, id, location ); |
---|
84 | |
---|
85 | done: |
---|
86 | return tp; |
---|
87 | } |
---|
88 | |
---|