1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @brief Constants and Structures Needed to Declare a Thread Queue |
---|
5 | * |
---|
6 | * This include file contains all the constants and structures |
---|
7 | * needed to declare a thread queue. |
---|
8 | */ |
---|
9 | |
---|
10 | /* |
---|
11 | * COPYRIGHT (c) 1989-2014. |
---|
12 | * On-Line Applications Research Corporation (OAR). |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * http://www.rtems.org/license/LICENSE. |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef _RTEMS_SCORE_THREADQ_H |
---|
20 | #define _RTEMS_SCORE_THREADQ_H |
---|
21 | |
---|
22 | #include <rtems/score/chain.h> |
---|
23 | #include <rtems/score/isrlock.h> |
---|
24 | #include <rtems/score/priority.h> |
---|
25 | #include <rtems/score/rbtree.h> |
---|
26 | |
---|
27 | #ifdef __cplusplus |
---|
28 | extern "C" { |
---|
29 | #endif |
---|
30 | |
---|
31 | /** |
---|
32 | * @defgroup ScoreThreadQueue Thread Queue Handler |
---|
33 | * |
---|
34 | * @ingroup Score |
---|
35 | * |
---|
36 | * This handler provides the capability to have threads block in |
---|
37 | * ordered sets. The sets may be ordered using the FIFO or priority |
---|
38 | * discipline. |
---|
39 | */ |
---|
40 | /**@{*/ |
---|
41 | |
---|
42 | typedef struct _Thread_Control Thread_Control; |
---|
43 | |
---|
44 | typedef struct { |
---|
45 | /** This union contains the data structures used to manage the blocked |
---|
46 | * set of tasks which varies based upon the discipline. |
---|
47 | */ |
---|
48 | union { |
---|
49 | /** This is the FIFO discipline list. */ |
---|
50 | Chain_Control Fifo; |
---|
51 | /** This is the set of threads for priority discipline waiting. */ |
---|
52 | RBTree_Control Priority; |
---|
53 | } Heads; |
---|
54 | |
---|
55 | Chain_Control Free_chain; |
---|
56 | |
---|
57 | Chain_Node Free_node; |
---|
58 | } Thread_queue_Heads; |
---|
59 | |
---|
60 | typedef struct { |
---|
61 | Thread_queue_Heads *heads; |
---|
62 | |
---|
63 | /** |
---|
64 | * @brief Lock to protect this thread queue. |
---|
65 | * |
---|
66 | * It may be used to protect additional state of the object embedding this |
---|
67 | * thread queue. |
---|
68 | * |
---|
69 | * @see _Thread_queue_Acquire(), _Thread_queue_Acquire_critical() and |
---|
70 | * _Thread_queue_Release(). |
---|
71 | */ |
---|
72 | ISR_LOCK_MEMBER( Lock ) |
---|
73 | } Thread_queue_Queue; |
---|
74 | |
---|
75 | /** |
---|
76 | * @brief Thread queue priority change operation. |
---|
77 | * |
---|
78 | * @param[in] the_thread The thread. |
---|
79 | * @param[in] new_priority The new priority value. |
---|
80 | * @param[in] queue The actual thread queue. |
---|
81 | * |
---|
82 | * @see Thread_queue_Operations. |
---|
83 | */ |
---|
84 | typedef void ( *Thread_queue_Priority_change_operation )( |
---|
85 | Thread_Control *the_thread, |
---|
86 | Priority_Control new_priority, |
---|
87 | Thread_queue_Queue *queue |
---|
88 | ); |
---|
89 | |
---|
90 | /** |
---|
91 | * @brief Thread queue enqueue operation. |
---|
92 | * |
---|
93 | * @param[in] queue The actual thread queue. |
---|
94 | * @param[in] the_thread The thread to enqueue on the queue. |
---|
95 | * |
---|
96 | * @see _Thread_Wait_set_operations(). |
---|
97 | */ |
---|
98 | typedef void ( *Thread_queue_Enqueue_operation )( |
---|
99 | Thread_queue_Queue *queue, |
---|
100 | Thread_Control *the_thread |
---|
101 | ); |
---|
102 | |
---|
103 | /** |
---|
104 | * @brief Thread queue extract operation. |
---|
105 | * |
---|
106 | * @param[in] queue The actual thread queue. |
---|
107 | * @param[in] the_thread The thread to extract from the thread queue. |
---|
108 | * |
---|
109 | * @see _Thread_Wait_set_operations(). |
---|
110 | */ |
---|
111 | typedef void ( *Thread_queue_Extract_operation )( |
---|
112 | Thread_queue_Queue *queue, |
---|
113 | Thread_Control *the_thread |
---|
114 | ); |
---|
115 | |
---|
116 | /** |
---|
117 | * @brief Thread queue first operation. |
---|
118 | * |
---|
119 | * @param[in] heads The thread queue heads. |
---|
120 | * |
---|
121 | * @retval NULL No thread is present on the thread queue. |
---|
122 | * @retval first The first thread of the thread queue according to the insert |
---|
123 | * order. This thread remains on the thread queue. |
---|
124 | * |
---|
125 | * @see _Thread_Wait_set_operations(). |
---|
126 | */ |
---|
127 | typedef Thread_Control *( *Thread_queue_First_operation )( |
---|
128 | Thread_queue_Heads *heads |
---|
129 | ); |
---|
130 | |
---|
131 | /** |
---|
132 | * @brief Thread queue operations. |
---|
133 | * |
---|
134 | * @see _Thread_wait_Set_operations(). |
---|
135 | */ |
---|
136 | typedef struct { |
---|
137 | /** |
---|
138 | * @brief Thread queue priority change operation. |
---|
139 | * |
---|
140 | * Called by _Thread_Change_priority() to notify a thread about a priority |
---|
141 | * change. In case this thread waits currently for a resource the handler |
---|
142 | * may adjust its data structures according to the new priority value. This |
---|
143 | * handler must not be NULL, instead the default handler |
---|
144 | * _Thread_Do_nothing_priority_change() should be used in case nothing needs |
---|
145 | * to be done during a priority change. |
---|
146 | */ |
---|
147 | Thread_queue_Priority_change_operation priority_change; |
---|
148 | |
---|
149 | /** |
---|
150 | * @brief Thread queue enqueue operation. |
---|
151 | * |
---|
152 | * Called by object routines to enqueue the thread. |
---|
153 | */ |
---|
154 | Thread_queue_Enqueue_operation enqueue; |
---|
155 | |
---|
156 | /** |
---|
157 | * @brief Thread queue extract operation. |
---|
158 | * |
---|
159 | * Called by object routines to extract a thread from a thread queue. |
---|
160 | */ |
---|
161 | Thread_queue_Extract_operation extract; |
---|
162 | |
---|
163 | /** |
---|
164 | * @brief Thread queue first operation. |
---|
165 | */ |
---|
166 | Thread_queue_First_operation first; |
---|
167 | } Thread_queue_Operations; |
---|
168 | |
---|
169 | /** |
---|
170 | * The following enumerated type details all of the disciplines |
---|
171 | * supported by the Thread Queue Handler. |
---|
172 | */ |
---|
173 | typedef enum { |
---|
174 | THREAD_QUEUE_DISCIPLINE_FIFO, /* FIFO queue discipline */ |
---|
175 | THREAD_QUEUE_DISCIPLINE_PRIORITY /* PRIORITY queue discipline */ |
---|
176 | } Thread_queue_Disciplines; |
---|
177 | |
---|
178 | /** |
---|
179 | * This is the structure used to manage sets of tasks which are blocked |
---|
180 | * waiting to acquire a resource. |
---|
181 | */ |
---|
182 | typedef struct { |
---|
183 | /** |
---|
184 | * @brief The actual thread queue. |
---|
185 | */ |
---|
186 | Thread_queue_Queue Queue; |
---|
187 | |
---|
188 | /** |
---|
189 | * @brief The operations for the actual thread queue. |
---|
190 | */ |
---|
191 | const Thread_queue_Operations *operations; |
---|
192 | } Thread_queue_Control; |
---|
193 | |
---|
194 | /**@}*/ |
---|
195 | |
---|
196 | #ifdef __cplusplus |
---|
197 | } |
---|
198 | #endif |
---|
199 | |
---|
200 | #endif |
---|
201 | /* end of include file */ |
---|