Changeset 4c8a0ac in rtems


Ignore:
Timestamp:
Mar 4, 2015, 7:02:09 AM (5 years ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
4.11, master
Children:
7d6e94b
Parents:
5b393fa5
git-author:
Sebastian Huber <sebastian.huber@…> (03/04/15 07:02:09)
git-committer:
Sebastian Huber <sebastian.huber@…> (03/05/15 10:36:45)
Message:

score: Add thread wait flags

Update #2273.

Location:
cpukit/score
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpukit/score/include/rtems/score/thread.h

    r5b393fa5 r4c8a0ac  
    2222#define _RTEMS_SCORE_THREAD_H
    2323
     24#include <rtems/score/atomic.h>
    2425#include <rtems/score/context.h>
    2526#if defined(RTEMS_MULTIPROCESSING)
     
    263264
    264265/**
     266 * @brief This type is able to contain several flags used to control the wait
     267 * class and state of a thread.
     268 *
     269 * The mutually exclusive wait class flags are
     270 * - @ref THREAD_WAIT_CLASS_EVENT,
     271 * - @ref THREAD_WAIT_CLASS_SYSTEM_EVENT, and
     272 * - @ref THREAD_WAIT_CLASS_OBJECT.
     273 *
     274 * The mutually exclusive wait state flags are
     275 * - @ref THREAD_WAIT_STATE_INTEND_TO_BLOCK,
     276 * - @ref THREAD_WAIT_STATE_BLOCKED,
     277 * - @ref THREAD_WAIT_STATE_SATISFIED,
     278 * - @ref THREAD_WAIT_STATE_TIMEOUT,
     279 * - @ref THREAD_WAIT_STATE_INTERRUPT_SATISFIED, and
     280 * - @ref THREAD_WAIT_STATE_INTERRUPT_TIMEOUT,
     281 */
     282typedef unsigned int Thread_Wait_flags;
     283
     284/**
    265285 *  @brief Information required to manage a thread while it is blocked.
    266286 *
     
    289309  /** This field points to the thread queue on which this thread is blocked. */
    290310  Thread_queue_Control *queue;
     311
     312  /**
     313   * @brief This field contains several flags used to control the wait class
     314   * and state of a thread in case fine-grained locking is used.
     315   */
     316#if defined(RTEMS_SMP)
     317  Atomic_Uint           flags;
     318#else
     319  Thread_Wait_flags     flags;
     320#endif
    291321}   Thread_Wait_information;
    292322
  • cpukit/score/include/rtems/score/threadimpl.h

    r5b393fa5 r4c8a0ac  
    924924}
    925925
     926/**
     927 * @brief The initial thread wait flags value set by _Thread_Initialize().
     928 */
     929#define THREAD_WAIT_FLAGS_INITIAL 0x0U
     930
     931/**
     932 * @brief Mask to get the thread wait state flags.
     933 */
     934#define THREAD_WAIT_STATE_MASK 0xffU
     935
     936/**
     937 * @brief Indicates that the thread begins with the blocking operation.
     938 *
     939 * A blocking operation consists of an optional watchdog initialization and the
     940 * setting of the appropriate thread blocking state with the corresponding
     941 * scheduler block operation.
     942 */
     943#define THREAD_WAIT_STATE_INTEND_TO_BLOCK 0x1U
     944
     945/**
     946 * @brief Indicates that the thread completed the blocking operation.
     947 */
     948#define THREAD_WAIT_STATE_BLOCKED 0x2U
     949
     950/**
     951 * @brief Indicates that the thread progress condition is satisfied and it is
     952 * ready to resume execution.
     953 */
     954#define THREAD_WAIT_STATE_SATISFIED 0x4U
     955
     956/**
     957 * @brief Indicates that a timeout occurred and the thread is ready to resume
     958 * execution.
     959 */
     960#define THREAD_WAIT_STATE_TIMEOUT 0x8U
     961
     962/**
     963 * @brief Indicates that the thread progress condition was satisfied during the
     964 * blocking operation and it is ready to resume execution.
     965 */
     966#define THREAD_WAIT_STATE_INTERRUPT_SATISFIED 0x10U
     967
     968/**
     969 * @brief Indicates that a timeout occurred during the blocking operation and
     970 * the thread is ready to resume execution.
     971 */
     972#define THREAD_WAIT_STATE_INTERRUPT_TIMEOUT 0x20U
     973
     974/**
     975 * @brief Mask to get the thread wait class flags.
     976 */
     977#define THREAD_WAIT_CLASS_MASK 0xff00U
     978
     979/**
     980 * @brief Indicates that the thread waits for an event.
     981 */
     982#define THREAD_WAIT_CLASS_EVENT 0x100U
     983
     984/**
     985 * @brief Indicates that the thread waits for a system event.
     986 */
     987#define THREAD_WAIT_CLASS_SYSTEM_EVENT 0x200U
     988
     989/**
     990 * @brief Indicates that the thread waits for a object.
     991 */
     992#define THREAD_WAIT_CLASS_OBJECT 0x400U
     993
     994RTEMS_INLINE_ROUTINE void _Thread_Wait_flags_set(
     995  Thread_Control    *the_thread,
     996  Thread_Wait_flags  flags
     997)
     998{
     999#if defined(RTEMS_SMP)
     1000  _Atomic_Store_uint( &the_thread->Wait.flags, flags, ATOMIC_ORDER_RELAXED );
     1001#else
     1002  the_thread->Wait.flags = flags;
     1003#endif
     1004}
     1005
     1006RTEMS_INLINE_ROUTINE Thread_Wait_flags _Thread_Wait_flags_get(
     1007  const Thread_Control *the_thread
     1008)
     1009{
     1010#if defined(RTEMS_SMP)
     1011  return _Atomic_Load_uint( &the_thread->Wait.flags, ATOMIC_ORDER_RELAXED );
     1012#else
     1013  return the_thread->Wait.flags;
     1014#endif
     1015}
     1016
     1017/**
     1018 * @brief Tries to change the thread wait flags inside a critical section
     1019 * (interrupts disabled).
     1020 *
     1021 * In case the wait flags are equal to the expected wait flags, then the wait
     1022 * flags are set to the desired wait flags.
     1023 *
     1024 * @param[in] the_thread The thread.
     1025 * @param[in] expected_flags The expected wait flags.
     1026 * @param[in] desired_flags The desired wait flags.
     1027 *
     1028 * @retval true The wait flags were equal to the expected wait flags.
     1029 * @retval false Otherwise.
     1030 */
     1031RTEMS_INLINE_ROUTINE bool _Thread_Wait_flags_try_change_critical(
     1032  Thread_Control    *the_thread,
     1033  Thread_Wait_flags  expected_flags,
     1034  Thread_Wait_flags  desired_flags
     1035)
     1036{
     1037#if defined(RTEMS_SMP)
     1038  return _Atomic_Compare_exchange_uint(
     1039    &the_thread->Wait.flags,
     1040    &expected_flags,
     1041    desired_flags,
     1042    ATOMIC_ORDER_RELAXED,
     1043    ATOMIC_ORDER_RELAXED
     1044  );
     1045#else
     1046  bool success = the_thread->Wait.flags == expected_flags;
     1047
     1048  if ( success ) {
     1049    the_thread->Wait.flags = desired_flags;
     1050  }
     1051
     1052  return success;
     1053#endif
     1054}
     1055
     1056/**
     1057 * @brief Tries to change the thread wait flags.
     1058 *
     1059 * @see _Thread_Wait_flags_try_change_critical().
     1060 */
     1061RTEMS_INLINE_ROUTINE bool _Thread_Wait_flags_try_change(
     1062  Thread_Control    *the_thread,
     1063  Thread_Wait_flags  expected_flags,
     1064  Thread_Wait_flags  desired_flags
     1065)
     1066{
     1067  bool success;
     1068#if !defined(RTEMS_SMP)
     1069  ISR_Level level;
     1070
     1071  _ISR_Disable_without_giant( level );
     1072#endif
     1073
     1074  success = _Thread_Wait_flags_try_change_critical(
     1075    the_thread,
     1076    expected_flags,
     1077    desired_flags
     1078  );
     1079
     1080#if !defined(RTEMS_SMP)
     1081  _ISR_Enable_without_giant( level );
     1082#endif
     1083
     1084  return success;
     1085}
     1086
    9261087RTEMS_INLINE_ROUTINE void _Thread_Debug_set_real_processor(
    9271088  Thread_Control  *the_thread,
  • cpukit/score/src/threadinitialize.c

    r5b393fa5 r4c8a0ac  
    201201  the_thread->Start.initial_priority  = priority;
    202202
     203  _Thread_Wait_flags_set( the_thread, THREAD_WAIT_FLAGS_INITIAL );
     204
    203205  _Scheduler_Node_initialize( scheduler, the_thread );
    204206  scheduler_node_initialized = true;
Note: See TracChangeset for help on using the changeset viewer.