summaryrefslogtreecommitdiffstats
path: root/cpukit/include/rtems/score/schedulerprioritysmpimpl.h
blob: 17d6e552f3ea7ea1e4fc55f364b77abc7ba0e63d (plain) (blame)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/**
 * @file
 *
 * @ingroup ScoreSchedulerPrioritySMP
 *
 * @brief Deterministic Priority SMP Scheduler API
 */

/*
 * Copyright (c) 2013, 2017 embedded brains GmbH.  All rights reserved.
 *
 *  embedded brains GmbH
 *  Dornierstr. 4
 *  82178 Puchheim
 *  Germany
 *  <rtems@embedded-brains.de>
 *
 * 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.
 */

#ifndef _RTEMS_SCORE_SCHEDULERPRIORITYSMPIMPL_H
#define _RTEMS_SCORE_SCHEDULERPRIORITYSMPIMPL_H

#include <rtems/score/schedulerprioritysmp.h>
#include <rtems/score/schedulerpriorityimpl.h>
#include <rtems/score/schedulersimpleimpl.h>
#include <rtems/score/schedulersmpimpl.h>

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/**
 * @ingroup ScoreSchedulerPrioritySMP
 * @{
 */

static inline Scheduler_priority_SMP_Context *_Scheduler_priority_SMP_Get_self(
  Scheduler_Context *context
)
{
  return (Scheduler_priority_SMP_Context *) context;
}

static inline Scheduler_priority_SMP_Node *_Scheduler_priority_SMP_Thread_get_node(
  Thread_Control *thread
)
{
  return (Scheduler_priority_SMP_Node *) _Thread_Scheduler_get_home_node( thread );
}

static inline Scheduler_priority_SMP_Node *
_Scheduler_priority_SMP_Node_downcast( Scheduler_Node *node )
{
  return (Scheduler_priority_SMP_Node *) node;
}

static inline bool _Scheduler_priority_SMP_Has_ready( Scheduler_Context *context )
{
  Scheduler_priority_SMP_Context *self =
    _Scheduler_priority_SMP_Get_self( context );

  return !_Priority_bit_map_Is_empty( &self->Bit_map );
}

static inline void _Scheduler_priority_SMP_Move_from_scheduled_to_ready(
  Scheduler_Context *context,
  Scheduler_Node    *scheduled_to_ready
)
{
  Scheduler_priority_SMP_Context *self =
    _Scheduler_priority_SMP_Get_self( context );
  Scheduler_priority_SMP_Node *node =
    _Scheduler_priority_SMP_Node_downcast( scheduled_to_ready );

  _Chain_Extract_unprotected( &node->Base.Base.Node.Chain );
  _Scheduler_priority_Ready_queue_enqueue_first(
    &node->Base.Base.Node.Chain,
    &node->Ready_queue,
    &self->Bit_map
  );
}

static inline void _Scheduler_priority_SMP_Move_from_ready_to_scheduled(
  Scheduler_Context *context,
  Scheduler_Node    *ready_to_scheduled
)
{
  Scheduler_priority_SMP_Context *self;
  Scheduler_priority_SMP_Node    *node;
  Priority_Control                insert_priority;

  self = _Scheduler_priority_SMP_Get_self( context );
  node = _Scheduler_priority_SMP_Node_downcast( ready_to_scheduled );

  _Scheduler_priority_Ready_queue_extract(
    &node->Base.Base.Node.Chain,
    &node->Ready_queue,
    &self->Bit_map
  );
  insert_priority = _Scheduler_SMP_Node_priority( &node->Base.Base );
  insert_priority = SCHEDULER_PRIORITY_APPEND( insert_priority );
  _Chain_Insert_ordered_unprotected(
    &self->Base.Scheduled,
    &node->Base.Base.Node.Chain,
    &insert_priority,
    _Scheduler_SMP_Priority_less_equal
  );
}

static inline void _Scheduler_priority_SMP_Insert_ready(
  Scheduler_Context *context,
  Scheduler_Node    *node_base,
  Priority_Control   insert_priority
)
{
  Scheduler_priority_SMP_Context *self;
  Scheduler_priority_SMP_Node    *node;

  self = _Scheduler_priority_SMP_Get_self( context );
  node = _Scheduler_priority_SMP_Node_downcast( node_base );

  if ( SCHEDULER_PRIORITY_IS_APPEND( insert_priority ) ) {
    _Scheduler_priority_Ready_queue_enqueue(
      &node->Base.Base.Node.Chain,
      &node->Ready_queue,
      &self->Bit_map
    );
  } else {
    _Scheduler_priority_Ready_queue_enqueue_first(
      &node->Base.Base.Node.Chain,
      &node->Ready_queue,
      &self->Bit_map
    );
  }
}

static inline void _Scheduler_priority_SMP_Extract_from_ready(
  Scheduler_Context *context,
  Scheduler_Node    *thread
)
{
  Scheduler_priority_SMP_Context *self =
    _Scheduler_priority_SMP_Get_self( context );
  Scheduler_priority_SMP_Node *node =
    _Scheduler_priority_SMP_Node_downcast( thread );

  _Scheduler_priority_Ready_queue_extract(
    &node->Base.Base.Node.Chain,
    &node->Ready_queue,
    &self->Bit_map
  );
}

static inline void _Scheduler_priority_SMP_Do_update(
  Scheduler_Context *context,
  Scheduler_Node    *node_to_update,
  Priority_Control   new_priority
)
{
  Scheduler_priority_SMP_Context *self;
  Scheduler_priority_SMP_Node    *node;

  self = _Scheduler_priority_SMP_Get_self( context );
  node = _Scheduler_priority_SMP_Node_downcast( node_to_update );

  _Scheduler_SMP_Node_update_priority( &node->Base, new_priority );
  _Scheduler_priority_Ready_queue_update(
    &node->Ready_queue,
    SCHEDULER_PRIORITY_UNMAP( new_priority ),
    &self->Bit_map,
    &self->Ready[ 0 ]
  );
}

/** @} */

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* _RTEMS_SCORE_SCHEDULERPRIORITYSMPIMPL_H */