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/score/threadimpl.h> |
---|
23 | |
---|
24 | Thread_Control *_Thread_Get ( |
---|
25 | Objects_Id id, |
---|
26 | Objects_Locations *location |
---|
27 | ) |
---|
28 | { |
---|
29 | uint32_t the_api; |
---|
30 | uint32_t the_class; |
---|
31 | Objects_Information **api_information; |
---|
32 | Objects_Information *information; |
---|
33 | Thread_Control *tp = (Thread_Control *) 0; |
---|
34 | |
---|
35 | if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) { |
---|
36 | _Thread_Disable_dispatch(); |
---|
37 | *location = OBJECTS_LOCAL; |
---|
38 | tp = _Thread_Executing; |
---|
39 | goto done; |
---|
40 | } |
---|
41 | |
---|
42 | the_api = _Objects_Get_API( id ); |
---|
43 | if ( !_Objects_Is_api_valid( the_api ) ) { |
---|
44 | *location = OBJECTS_ERROR; |
---|
45 | goto done; |
---|
46 | } |
---|
47 | |
---|
48 | the_class = _Objects_Get_class( id ); |
---|
49 | if ( the_class != 1 ) { /* threads are always first class :) */ |
---|
50 | *location = OBJECTS_ERROR; |
---|
51 | goto done; |
---|
52 | } |
---|
53 | |
---|
54 | api_information = _Objects_Information_table[ the_api ]; |
---|
55 | /* |
---|
56 | * There is no way for this to happen if POSIX is enabled. But there |
---|
57 | * is actually a test case in sp43 for this which trips it whether or |
---|
58 | * not POSIX is enabled. So in the interest of safety, this is left |
---|
59 | * on in all configurations. |
---|
60 | */ |
---|
61 | if ( !api_information ) { |
---|
62 | *location = OBJECTS_ERROR; |
---|
63 | goto done; |
---|
64 | } |
---|
65 | |
---|
66 | information = api_information[ the_class ]; |
---|
67 | if ( !information ) { |
---|
68 | *location = OBJECTS_ERROR; |
---|
69 | goto done; |
---|
70 | } |
---|
71 | |
---|
72 | tp = (Thread_Control *) _Objects_Get( information, id, location ); |
---|
73 | |
---|
74 | done: |
---|
75 | return tp; |
---|
76 | } |
---|
77 | |
---|