[d4d7899] | 1 | /** |
---|
| 2 | * @file |
---|
| 3 | * |
---|
| 4 | * @brief Maps Thread IDs to TCB Pointer |
---|
[78dabb69] | 5 | * |
---|
[d4d7899] | 6 | * @ingroup ScoreThread |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | /* |
---|
[b1e13f4] | 10 | * COPYRIGHT (c) 1989-2011. |
---|
[78dabb69] | 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * |
---|
| 13 | * The license and distribution terms for this file may be |
---|
[dcf3687] | 14 | * found in the file LICENSE in this distribution or at |
---|
[c499856] | 15 | * http://www.rtems.org/license/LICENSE. |
---|
[78dabb69] | 16 | */ |
---|
| 17 | |
---|
| 18 | #if HAVE_CONFIG_H |
---|
| 19 | #include "config.h" |
---|
| 20 | #endif |
---|
| 21 | |
---|
[5618c37a] | 22 | #include <rtems/score/threadimpl.h> |
---|
[78dabb69] | 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; |
---|
[d8d373a] | 31 | Objects_Information **api_information; |
---|
[78dabb69] | 32 | Objects_Information *information; |
---|
| 33 | Thread_Control *tp = (Thread_Control *) 0; |
---|
[28352fae] | 34 | |
---|
[78dabb69] | 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 | } |
---|
[28352fae] | 41 | |
---|
[78dabb69] | 42 | the_api = _Objects_Get_API( id ); |
---|
[52e70cf] | 43 | if ( !_Objects_Is_api_valid( the_api ) ) { |
---|
[78dabb69] | 44 | *location = OBJECTS_ERROR; |
---|
| 45 | goto done; |
---|
| 46 | } |
---|
[28352fae] | 47 | |
---|
[78dabb69] | 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 | } |
---|
[28352fae] | 53 | |
---|
[d8d373a] | 54 | api_information = _Objects_Information_table[ the_api ]; |
---|
[56e135a1] | 55 | /* |
---|
[b1e13f4] | 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. |
---|
[dacdda30] | 60 | */ |
---|
[b1e13f4] | 61 | if ( !api_information ) { |
---|
| 62 | *location = OBJECTS_ERROR; |
---|
| 63 | goto done; |
---|
| 64 | } |
---|
[d8d373a] | 65 | |
---|
| 66 | information = api_information[ the_class ]; |
---|
[78dabb69] | 67 | if ( !information ) { |
---|
| 68 | *location = OBJECTS_ERROR; |
---|
| 69 | goto done; |
---|
| 70 | } |
---|
[28352fae] | 71 | |
---|
[78dabb69] | 72 | tp = (Thread_Control *) _Objects_Get( information, id, location ); |
---|
[28352fae] | 73 | |
---|
[78dabb69] | 74 | done: |
---|
| 75 | return tp; |
---|
| 76 | } |
---|
| 77 | |
---|