source: rtems/cpukit/score/src/threadsetstate.c

Last change on this file was 2a1449c, checked in by Joel Sherrill <joel@…>, on 02/16/22 at 21:09:32

score/src/[t-z]*.c: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSScoreThread
7 *
8 * @brief This source file contains the implementation of
9 *   _Thread_Set_state_locked() and _Thread_Set_state.
10 */
11
12/*
13 *  Thread Handler / Thread Set State
14 *
15 *  COPYRIGHT (c) 1989-2011.
16 *  On-Line Applications Research Corporation (OAR).
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions
20 * are met:
21 * 1. Redistributions of source code must retain the above copyright
22 *    notice, this list of conditions and the following disclaimer.
23 * 2. Redistributions in binary form must reproduce the above copyright
24 *    notice, this list of conditions and the following disclaimer in the
25 *    documentation and/or other materials provided with the distribution.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
31 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40#ifdef HAVE_CONFIG_H
41#include "config.h"
42#endif
43
44#include <rtems/score/threadimpl.h>
45#include <rtems/score/assert.h>
46#include <rtems/score/schedulerimpl.h>
47
48States_Control _Thread_Set_state_locked(
49  Thread_Control *the_thread,
50  States_Control  state
51)
52{
53  States_Control previous_state;
54  States_Control next_state;
55
56  _Assert( state != 0 );
57  _Assert( _Thread_State_is_owner( the_thread ) );
58
59  previous_state = the_thread->current_state;
60  next_state = _States_Set( state, previous_state);
61  the_thread->current_state = next_state;
62
63  if ( _States_Is_ready( previous_state ) ) {
64    _Scheduler_Block( the_thread );
65  }
66
67  return previous_state;
68}
69
70States_Control _Thread_Set_state(
71  Thread_Control *the_thread,
72  States_Control  state
73)
74{
75  ISR_lock_Context lock_context;
76  States_Control   previous_state;
77
78  _Thread_State_acquire( the_thread, &lock_context );
79  previous_state = _Thread_Set_state_locked( the_thread, state );
80  _Thread_State_release( the_thread, &lock_context );
81
82  return previous_state;
83}
Note: See TracBrowser for help on using the repository browser.