source: rtems/cpukit/score/src/threadqops.c @ e2735012

5
Last change on this file since e2735012 was e2735012, checked in by Sebastian Huber <sebastian.huber@…>, on 06/24/15 at 09:05:39

score: Introduce Thread_queue_Queue

Separate the thread queue heads and lock from the operations. This
enables the support for light weight objects which only support one
queuing discipline.

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/*
2 * Copyright (c) 2015 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#if HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <rtems/score/threadimpl.h>
20#include <rtems/score/chainimpl.h>
21#include <rtems/score/rbtreeimpl.h>
22
23static void _Thread_queue_Do_nothing_priority_change(
24  Thread_Control     *the_thread,
25  Priority_Control    new_priority,
26  Thread_queue_Queue *queue
27)
28{
29  /* Do nothing */
30}
31
32static void _Thread_queue_Do_nothing_extract(
33  Thread_queue_Queue *queue,
34  Thread_Control    *the_thread
35)
36{
37  /* Do nothing */
38}
39
40static void _Thread_queue_FIFO_initialize(
41  Thread_queue_Queue *queue
42)
43{
44  _Chain_Initialize_empty( &queue->Heads.Fifo );
45}
46
47static void _Thread_queue_FIFO_enqueue(
48  Thread_queue_Queue *queue,
49  Thread_Control     *the_thread
50)
51{
52  _Chain_Append_unprotected(
53    &queue->Heads.Fifo,
54    &the_thread->Wait.Node.Chain
55  );
56}
57
58static void _Thread_queue_FIFO_extract(
59  Thread_queue_Queue *queue,
60  Thread_Control     *the_thread
61)
62{
63  _Chain_Extract_unprotected( &the_thread->Wait.Node.Chain );
64}
65
66static Thread_Control *_Thread_queue_FIFO_first(
67  Thread_queue_Queue *queue
68)
69{
70  Chain_Control *fifo = &queue->Heads.Fifo;
71
72  return _Chain_Is_empty( fifo ) ?
73    NULL : THREAD_CHAIN_NODE_TO_THREAD( _Chain_First( fifo ) );
74}
75
76static void _Thread_queue_Priority_priority_change(
77  Thread_Control     *the_thread,
78  Priority_Control    new_priority,
79  Thread_queue_Queue *queue
80)
81{
82  _RBTree_Extract(
83    &queue->Heads.Priority,
84    &the_thread->Wait.Node.RBTree
85  );
86  _RBTree_Insert(
87    &queue->Heads.Priority,
88    &the_thread->Wait.Node.RBTree,
89    _Thread_queue_Compare_priority,
90    false
91  );
92}
93
94static void _Thread_queue_Priority_initialize(
95  Thread_queue_Queue *queue
96)
97{
98  _RBTree_Initialize_empty( &queue->Heads.Priority );
99}
100
101static void _Thread_queue_Priority_enqueue(
102  Thread_queue_Queue *queue,
103  Thread_Control     *the_thread
104)
105{
106  _RBTree_Insert(
107    &queue->Heads.Priority,
108    &the_thread->Wait.Node.RBTree,
109    _Thread_queue_Compare_priority,
110    false
111  );
112}
113
114static void _Thread_queue_Priority_extract(
115  Thread_queue_Queue *queue,
116  Thread_Control     *the_thread
117)
118{
119  _RBTree_Extract(
120    &queue->Heads.Priority,
121    &the_thread->Wait.Node.RBTree
122  );
123}
124
125static Thread_Control *_Thread_queue_Priority_first(
126  Thread_queue_Queue *queue
127)
128{
129  RBTree_Node *first;
130
131  first = _RBTree_First( &queue->Heads.Priority, RBT_LEFT );
132
133  return first != NULL ? THREAD_RBTREE_NODE_TO_THREAD( first ) : NULL;
134}
135
136const Thread_queue_Operations _Thread_queue_Operations_default = {
137  .priority_change = _Thread_queue_Do_nothing_priority_change,
138  .extract = _Thread_queue_Do_nothing_extract
139  /*
140   * The default operations are only used in _Thread_Change_priority() and
141   * _Thread_Timeout() and don't have a thread queue associated with them, so
142   * the enqueue and first operations are superfluous.
143   */
144};
145
146const Thread_queue_Operations _Thread_queue_Operations_FIFO = {
147  .priority_change = _Thread_queue_Do_nothing_priority_change,
148  .initialize = _Thread_queue_FIFO_initialize,
149  .enqueue = _Thread_queue_FIFO_enqueue,
150  .extract = _Thread_queue_FIFO_extract,
151  .first = _Thread_queue_FIFO_first
152};
153
154const Thread_queue_Operations _Thread_queue_Operations_priority = {
155  .priority_change = _Thread_queue_Priority_priority_change,
156  .initialize = _Thread_queue_Priority_initialize,
157  .enqueue = _Thread_queue_Priority_enqueue,
158  .extract = _Thread_queue_Priority_extract,
159  .first = _Thread_queue_Priority_first
160};
Note: See TracBrowser for help on using the repository browser.