source: rtems/cpukit/score/src/threadget.c @ 5b393fa5

4.115
Last change on this file since 5b393fa5 was 5b393fa5, checked in by Sebastian Huber <sebastian.huber@…>, on 03/01/15 at 12:50:55

score: Add thread acquire

Update #2273.

  • Property mode set to 100644
File size: 2.6 KB
Line 
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.org/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/score/threadimpl.h>
23
24static Objects_Information *_Thread_Get_objects_information(
25  Objects_Id id
26)
27{
28  uint32_t             the_api;
29  uint32_t             the_class;
30  Objects_Information **api_information;
31
32  the_api = _Objects_Get_API( id );
33  if ( !_Objects_Is_api_valid( the_api ) ) {
34    return NULL;
35  }
36
37  the_class = _Objects_Get_class( id );
38  if ( the_class != 1 ) {       /* threads are always first class :) */
39    return NULL;
40  }
41
42  api_information = _Objects_Information_table[ the_api ];
43  /*
44   *  There is no way for this to happen if POSIX is enabled.  But there
45   *  is actually a test case in sp43 for this which trips it whether or
46   *  not POSIX is enabled.  So in the interest of safety, this is left
47   *  on in all configurations.
48   */
49  if ( !api_information ) {
50    return NULL;
51  }
52
53  return api_information[ the_class ];
54}
55
56Thread_Control *_Thread_Get(
57  Objects_Id         id,
58  Objects_Locations *location
59)
60{
61  Objects_Information *information;
62
63  if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) {
64    _Thread_Disable_dispatch();
65    *location = OBJECTS_LOCAL;
66    return _Thread_Executing;
67  }
68
69  information = _Thread_Get_objects_information( id );
70  if ( information == NULL ) {
71    *location = OBJECTS_ERROR;
72    return NULL;
73  }
74
75  return (Thread_Control *) _Objects_Get( information, id, location );
76}
77
78Thread_Control *_Thread_Acquire_executing( ISR_lock_Context *lock_context )
79{
80  Thread_Control *executing;
81
82#if defined(RTEMS_SMP)
83  _ISR_Disable_without_giant( lock_context->Lock_context.isr_level );
84#else
85  _ISR_Disable( lock_context->isr_level );
86#endif
87  executing = _Thread_Executing;
88  _ISR_lock_Acquire( &executing->Object.Lock, lock_context );
89
90  return executing;
91}
92
93Thread_Control *_Thread_Acquire(
94  Objects_Id         id,
95  Objects_Locations *location,
96  ISR_lock_Context  *lock_context
97)
98{
99  Objects_Information *information;
100
101  if ( _Objects_Are_ids_equal( id, OBJECTS_ID_OF_SELF ) ) {
102    *location = OBJECTS_LOCAL;
103    return _Thread_Acquire_executing( lock_context );
104  }
105
106  information = _Thread_Get_objects_information( id );
107  if ( information == NULL ) {
108    *location = OBJECTS_ERROR;
109    return NULL;
110  }
111
112  return (Thread_Control *)
113    _Objects_Acquire( information, id, location, lock_context );
114}
Note: See TracBrowser for help on using the repository browser.