source: rtems/cpukit/score/src/threadsetstate.c @ 1c2d178

5
Last change on this file since 1c2d178 was 9a99ce15, checked in by Sebastian Huber <sebastian.huber@…>, on 05/13/16 at 05:12:10

score: Add _Thread_Set_state_locked()

This makes it possible to do thread state and thread life changes
together under protection of the thread state lock.

Update #2555.
Update #2626.

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/**
2 * @file
3 *
4 * @brief Sets States for a Thread
5 *
6 * @ingroup ScoreThread
7 */
8
9/*
10 *  Thread Handler / Thread Set State
11 *
12 *  COPYRIGHT (c) 1989-2011.
13 *  On-Line Applications Research Corporation (OAR).
14 *
15 *  The license and distribution terms for this file may be
16 *  found in the file LICENSE in this distribution or at
17 *  http://www.rtems.org/license/LICENSE.
18 */
19
20#if HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <rtems/score/threadimpl.h>
25#include <rtems/score/assert.h>
26#include <rtems/score/schedulerimpl.h>
27
28States_Control _Thread_Set_state_locked(
29  Thread_Control *the_thread,
30  States_Control  state
31)
32{
33  States_Control previous_state;
34  States_Control next_state;
35
36  _Assert( state != 0 );
37  _Assert( _Thread_State_is_owner( the_thread ) );
38
39  previous_state = the_thread->current_state;
40  next_state = _States_Set( state, previous_state);
41  the_thread->current_state = next_state;
42
43  if ( _States_Is_ready( previous_state ) ) {
44    _Scheduler_Block( the_thread );
45  }
46
47  return previous_state;
48}
49
50States_Control _Thread_Set_state(
51  Thread_Control *the_thread,
52  States_Control  state
53)
54{
55  ISR_lock_Context lock_context;
56  States_Control   previous_state;
57
58  _Thread_State_acquire( the_thread, &lock_context );
59  previous_state = _Thread_Set_state_locked( the_thread, state );
60  _Thread_State_release( the_thread, &lock_context );
61
62  return previous_state;
63}
Note: See TracBrowser for help on using the repository browser.