1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
/**
* @file
*
* @brief Maps Thread IDs to TCB Pointer
*
* @ingroup ScoreThread
*/
/*
* COPYRIGHT (c) 1989-2011.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems/score/threadimpl.h>
static Objects_Information *_Thread_Get_objects_information(
Objects_Id id
)
{
uint32_t the_api;
uint32_t the_class;
Objects_Information **api_information;
the_api = _Objects_Get_API( id );
if ( !_Objects_Is_api_valid( the_api ) ) {
return NULL;
}
the_class = _Objects_Get_class( id );
if ( the_class != 1 ) { /* threads are always first class :) */
return NULL;
}
api_information = _Objects_Information_table[ the_api ];
/*
* There is no way for this to happen if POSIX is enabled. But there
* is actually a test case in sp43 for this which trips it whether or
* not POSIX is enabled. So in the interest of safety, this is left
* on in all configurations.
*/
if ( !api_information ) {
return NULL;
}
return api_information[ the_class ];
}
Thread_Control *_Thread_Get(
Objects_Id id,
Objects_Locations *location
)
{
Objects_Information *information;
if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) {
_Thread_Disable_dispatch();
*location = OBJECTS_LOCAL;
return _Thread_Executing;
}
information = _Thread_Get_objects_information( id );
if ( information == NULL ) {
*location = OBJECTS_ERROR;
return NULL;
}
return (Thread_Control *) _Objects_Get( information, id, location );
}
Thread_Control *_Thread_Acquire_executing( ISR_lock_Context *lock_context )
{
Thread_Control *executing;
#if defined(RTEMS_SMP)
_ISR_Disable_without_giant( lock_context->Lock_context.isr_level );
#else
_ISR_Disable( lock_context->isr_level );
#endif
executing = _Thread_Executing;
_ISR_lock_Acquire( &executing->Object.Lock, lock_context );
return executing;
}
Thread_Control *_Thread_Acquire(
Objects_Id id,
Objects_Locations *location,
ISR_lock_Context *lock_context
)
{
Objects_Information *information;
if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) {
*location = OBJECTS_LOCAL;
return _Thread_Acquire_executing( lock_context );
}
information = _Thread_Get_objects_information( id );
if ( information == NULL ) {
*location = OBJECTS_ERROR;
return NULL;
}
return (Thread_Control *)
_Objects_Acquire( information, id, location, lock_context );
}
|