RTEMS 6.1-rc4
Loading...
Searching...
No Matches
tx-thread-queue.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
12/*
13 * Copyright (C) 2021 embedded brains GmbH & Co. KG
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _TX_THREAD_QUEUE_H
38#define _TX_THREAD_QUEUE_H
39
40#include "tx-support.h"
41
43#include <rtems/score/atomic.h>
44#include <rtems/score/status.h>
45
46#include <setjmp.h>
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
58typedef enum {
59 TQ_NODE_ONLY,
60 TQ_NODE_VITAL,
61 TQ_NODE_DISPENSABLE
62} TQNodeKind;
63
64typedef enum {
65 TQ_WAIT_STATE_BLOCKED,
66 TQ_WAIT_STATE_INTEND_TO_BLOCK,
67 TQ_WAIT_STATE_READY_AGAIN
68} TQWaitState;
69
70typedef enum {
71 TQ_BLOCKER_A,
72 TQ_BLOCKER_B,
73 TQ_BLOCKER_C,
74 TQ_BLOCKER_D,
75 TQ_BLOCKER_E,
76 TQ_WORKER_F,
77 TQ_HELPER_A,
78 TQ_HELPER_B,
79 TQ_HELPER_C,
80 TQ_WORKER_COUNT
81} TQWorkerKind;
82
83typedef enum {
84 TQ_MUTEX_A,
85 TQ_MUTEX_B,
86 TQ_MUTEX_C,
87 TQ_MUTEX_D,
88 TQ_MUTEX_NO_PROTOCOL,
89 TQ_MUTEX_FIFO,
90 TQ_MUTEX_COUNT
91} TQMutex;
92
93typedef enum {
94 TQ_FIFO,
95 TQ_PRIORITY
96} TQDiscipline;
97
98typedef enum {
99 TQ_NO_WAIT,
100 TQ_WAIT_FOREVER,
101 TQ_WAIT_TIMED
102} TQWait;
103
104typedef enum {
105 TQ_DEADLOCK_STATUS,
106 TQ_DEADLOCK_FATAL
107} TQDeadlock;
108
109typedef enum {
110 TQ_EVENT_ENQUEUE_PREPARE = RTEMS_EVENT_0,
111 TQ_EVENT_ENQUEUE = RTEMS_EVENT_1,
112 TQ_EVENT_ENQUEUE_DONE = RTEMS_EVENT_2,
113 TQ_EVENT_SURRENDER = RTEMS_EVENT_3,
114 TQ_EVENT_RUNNER_SYNC = RTEMS_EVENT_4,
115 TQ_EVENT_RUNNER_SYNC_2 = RTEMS_EVENT_5,
116 TQ_EVENT_HELPER_A_SYNC = RTEMS_EVENT_6,
117 TQ_EVENT_HELPER_B_SYNC = RTEMS_EVENT_7,
118 TQ_EVENT_MUTEX_A_OBTAIN = RTEMS_EVENT_8,
119 TQ_EVENT_MUTEX_A_RELEASE = RTEMS_EVENT_9,
120 TQ_EVENT_MUTEX_B_OBTAIN = RTEMS_EVENT_10,
121 TQ_EVENT_MUTEX_B_RELEASE = RTEMS_EVENT_11,
122 TQ_EVENT_BUSY_WAIT = RTEMS_EVENT_12,
123 TQ_EVENT_FLUSH_ALL = RTEMS_EVENT_13,
124 TQ_EVENT_FLUSH_PARTIAL = RTEMS_EVENT_14,
125 TQ_EVENT_SCHEDULER_RECORD_START = RTEMS_EVENT_15,
126 TQ_EVENT_SCHEDULER_RECORD_STOP = RTEMS_EVENT_16,
127 TQ_EVENT_TIMEOUT = RTEMS_EVENT_17,
128 TQ_EVENT_MUTEX_NO_PROTOCOL_OBTAIN = RTEMS_EVENT_18,
129 TQ_EVENT_MUTEX_NO_PROTOCOL_RELEASE = RTEMS_EVENT_19,
130 TQ_EVENT_ENQUEUE_FATAL = RTEMS_EVENT_20,
131 TQ_EVENT_MUTEX_C_OBTAIN = RTEMS_EVENT_21,
132 TQ_EVENT_MUTEX_C_RELEASE = RTEMS_EVENT_22,
133 TQ_EVENT_MUTEX_FIFO_OBTAIN = RTEMS_EVENT_23,
134 TQ_EVENT_MUTEX_FIFO_RELEASE = RTEMS_EVENT_24,
135 TQ_EVENT_ENQUEUE_TIMED = RTEMS_EVENT_25,
136 TQ_EVENT_MUTEX_D_OBTAIN = RTEMS_EVENT_26,
137 TQ_EVENT_MUTEX_D_RELEASE = RTEMS_EVENT_27,
138 TQ_EVENT_PIN = RTEMS_EVENT_28,
139 TQ_EVENT_UNPIN = RTEMS_EVENT_29,
140 TQ_EVENT_COUNT = RTEMS_EVENT_30
141} TQEvent;
142
143typedef enum {
144 TQ_ENQUEUE_BLOCKS,
145 TQ_ENQUEUE_STICKY
146} TQEnqueueVariant;
147
148typedef struct TQContext {
152 TQDiscipline discipline;
153
159 TQWait wait;
160
164 TQEnqueueVariant enqueue_variant;
165
169 TQDeadlock deadlock;
170
175
180
184 rtems_id worker_id[ TQ_WORKER_COUNT ];
185
190 rtems_tcb *worker_tcb[ TQ_WORKER_COUNT ];
191
196 volatile bool event_received[ TQ_WORKER_COUNT ];
197
201 volatile bool busy_wait[ TQ_WORKER_COUNT ];
202
207 volatile bool done[ TQ_WORKER_COUNT ];
208
212 Atomic_Uint counter;
213
218 uint32_t worker_counter[ TQ_WORKER_COUNT ];
219
224 Status_Control status[ TQ_WORKER_COUNT ];
225
226 union {
232
238 };
239
244 rtems_id mutex_id[ TQ_MUTEX_COUNT ];
245
250
254 void ( *get_properties )( struct TQContext *, TQWorkerKind );
255
260
264 uint32_t how_many;
265
270 uint32_t flush_count;
271
277
281 void ( *enqueue_prepare )( struct TQContext * );
282
286 Status_Control ( *enqueue )( struct TQContext *, TQWait );
287
291 void ( *enqueue_done )( struct TQContext * );
292
297
306 uint32_t ( *flush )( struct TQContext *, uint32_t, bool );
307
311 rtems_tcb *( *get_owner )( struct TQContext * );
312} TQContext;
313
314void TQSend(
315 TQContext *ctx,
316 TQWorkerKind worker,
317 rtems_event_set events
318);
319
320void TQSendAndWaitForExecutionStop(
321 TQContext *ctx,
322 TQWorkerKind worker,
323 rtems_event_set events
324);
325
326void TQSendAndWaitForIntendToBlock(
327 TQContext *ctx,
328 TQWorkerKind worker,
329 rtems_event_set events
330);
331
332void TQSendAndWaitForExecutionStopOrIntendToBlock(
333 TQContext *ctx,
334 TQWorkerKind worker,
335 rtems_event_set events
336);
337
338void TQSendAndSynchronizeRunner(
339 TQContext *ctx,
340 TQWorkerKind worker,
341 rtems_event_set events
342);
343
344void TQWaitForEventsReceived( const TQContext *ctx, TQWorkerKind worker );
345
346void TQWaitForIntendToBlock( const TQContext *ctx, TQWorkerKind worker );
347
348void TQWaitForExecutionStop( const TQContext *ctx, TQWorkerKind worker );
349
350void TQClearDone( TQContext *ctx, TQWorkerKind worker );
351
352void TQWaitForDone( const TQContext *ctx, TQWorkerKind worker );
353
354void TQSynchronizeRunner( void );
355
356void TQSynchronizeRunner2( void );
357
358void TQResetCounter( TQContext *ctx );
359
360uint32_t TQGetCounter( const TQContext *ctx );
361
362uint32_t TQGetWorkerCounter( const TQContext *ctx, TQWorkerKind worker );
363
364void TQMutexObtain( const TQContext *ctx, TQMutex mutex );
365
366void TQMutexRelease( const TQContext *ctx, TQMutex mutex );
367
368void TQSetPriority(
369 const TQContext *ctx,
370 TQWorkerKind worker,
371 Priority priority
372);
373
374Priority TQGetPriority( const TQContext *ctx, TQWorkerKind worker );
375
376void TQSetScheduler(
377 const TQContext *ctx,
378 TQWorkerKind worker,
379 rtems_id scheduler_id,
380 Priority priority
381);
382
383void TQInitialize( TQContext *ctx );
384
385void TQDestroy( TQContext *ctx );
386
387void TQReset( TQContext *ctx );
388
389void TQSortMutexesByID( TQContext *ctx );
390
391void TQGetProperties( TQContext *ctx, TQWorkerKind enqueued_worker );
392
393Status_Control TQConvertStatus( TQContext *ctx, Status_Control status );
394
395void TQEnqueuePrepare( TQContext *ctx );
396
397Status_Control TQEnqueue( TQContext *ctx, TQWait wait );
398
399Status_Control TQEnqueueFatal( TQContext *ctx );
400
401void TQEnqueueDone( TQContext *ctx );
402
403Status_Control TQSurrender( TQContext *ctx );
404
405void TQFlush( TQContext *ctx, bool flush_all );
406
407rtems_tcb *TQGetOwner( TQContext *ctx );
408
409void TQSchedulerRecordStart( TQContext *ctx );
410
411void TQSchedulerRecordStop( TQContext *ctx );
412
413const T_scheduler_event *TQGetNextAny( TQContext *ctx, size_t *index );
414
415const T_scheduler_event *TQGetNextBlock( TQContext *ctx, size_t *index );
416
417const T_scheduler_event *TQGetNextUnblock( TQContext *ctx, size_t *index );
418
419const T_scheduler_event *TQGetNextUpdatePriority(
420 TQContext *ctx,
421 size_t *index
422);
423
424const T_scheduler_event *TQGetNextAskForHelp( TQContext *ctx, size_t *index );
425
426void TQDoNothing( TQContext *ctx );
427
428Status_Control TQDoNothingSuccessfully( TQContext *ctx );
429
430Status_Control TQConvertStatusClassic( Status_Control status );
431
432Status_Control TQConvertStatusPOSIX( Status_Control status );
433
434void TQEnqueuePrepareDefault( TQContext *ctx );
435
436void TQEnqueueDoneDefault( TQContext *ctx );
437
438Status_Control TQEnqueueClassicSem( TQContext *ctx, TQWait wait );
439
440Status_Control TQSurrenderClassicSem( TQContext *ctx );
441
442rtems_tcb *TQGetOwnerClassicSem( TQContext *ctx );
443
444typedef enum {
445 TQ_SEM_BINARY,
446 TQ_SEM_COUNTING
447} TQSemVariant;
448
449typedef struct TQSemContext {
454
458 TQSemVariant variant;
459
463 uint32_t ( *get_count )( struct TQSemContext * );
464
468 void ( *set_count )( struct TQSemContext *, uint32_t );
470
471Status_Control TQSemSurrender( TQSemContext *ctx );
472
473uint32_t TQSemGetCount( TQSemContext *ctx );
474
475void TQSemSetCount( TQSemContext *ctx, uint32_t count );
476
477Status_Control TQSemSurrenderClassic( TQSemContext *ctx );
478
479uint32_t TQSemGetCountClassic( TQSemContext *ctx );
480
481void TQSemSetCountClassic( TQSemContext *ctx, uint32_t count );
482
483typedef enum {
484 TQ_MTX_NO_PROTOCOL,
485 TQ_MTX_PRIORITY_INHERIT,
486 TQ_MTX_PRIORITY_CEILING,
487 TQ_MTX_MRSP
488} TQMtxProtocol;
489
490typedef enum {
491 TQ_MTX_RECURSIVE_ALLOWED,
492 TQ_MTX_RECURSIVE_DEADLOCK,
493 TQ_MTX_RECURSIVE_UNAVAILABLE
494} TQMtxRecursive;
495
496typedef enum {
497 TQ_MTX_NO_OWNER_CHECK,
498 TQ_MTX_CHECKS_OWNER
499} TQMtxOwnerCheck;
500
501typedef struct TQMtxContext {
506
510 TQMtxProtocol protocol;
511
515 TQMtxRecursive recursive;
516
520 TQMtxOwnerCheck owner_check;
521
530
533#ifdef __cplusplus
534}
535#endif
536
537#endif /* _TX_THREAD_QUEUE_H */
#define RTEMS_EVENT_22
This event set constant represents the bit in the event set associated with event 22.
Definition: event.h:326
#define RTEMS_EVENT_15
This event set constant represents the bit in the event set associated with event 15.
Definition: event.h:256
#define RTEMS_EVENT_28
This event set constant represents the bit in the event set associated with event 28.
Definition: event.h:386
#define RTEMS_EVENT_29
This event set constant represents the bit in the event set associated with event 29.
Definition: event.h:396
#define RTEMS_EVENT_5
This event set constant represents the bit in the event set associated with event 5.
Definition: event.h:156
#define RTEMS_EVENT_21
This event set constant represents the bit in the event set associated with event 21.
Definition: event.h:316
#define RTEMS_EVENT_0
This event set constant represents the bit in the event set associated with event 0.
Definition: event.h:106
#define RTEMS_EVENT_9
This event set constant represents the bit in the event set associated with event 9.
Definition: event.h:196
#define RTEMS_EVENT_7
This event set constant represents the bit in the event set associated with event 7.
Definition: event.h:176
#define RTEMS_EVENT_10
This event set constant represents the bit in the event set associated with event 10.
Definition: event.h:206
#define RTEMS_EVENT_3
This event set constant represents the bit in the event set associated with event 3.
Definition: event.h:136
#define RTEMS_EVENT_16
This event set constant represents the bit in the event set associated with event 16.
Definition: event.h:266
#define RTEMS_EVENT_17
This event set constant represents the bit in the event set associated with event 17.
Definition: event.h:276
#define RTEMS_EVENT_12
This event set constant represents the bit in the event set associated with event 12.
Definition: event.h:226
#define RTEMS_EVENT_24
This event set constant represents the bit in the event set associated with event 24.
Definition: event.h:346
#define RTEMS_EVENT_19
This event set constant represents the bit in the event set associated with event 19.
Definition: event.h:296
#define RTEMS_EVENT_27
This event set constant represents the bit in the event set associated with event 27.
Definition: event.h:376
#define RTEMS_EVENT_20
This event set constant represents the bit in the event set associated with event 20.
Definition: event.h:306
#define RTEMS_EVENT_30
This event set constant represents the bit in the event set associated with event 30.
Definition: event.h:406
#define RTEMS_EVENT_1
This event set constant represents the bit in the event set associated with event 1.
Definition: event.h:116
#define RTEMS_EVENT_11
This event set constant represents the bit in the event set associated with event 11.
Definition: event.h:216
#define RTEMS_EVENT_4
This event set constant represents the bit in the event set associated with event 4.
Definition: event.h:146
#define RTEMS_EVENT_18
This event set constant represents the bit in the event set associated with event 18.
Definition: event.h:286
#define RTEMS_EVENT_14
This event set constant represents the bit in the event set associated with event 14.
Definition: event.h:246
uint32_t rtems_event_set
This integer type represents a bit field which can hold exactly 32 individual events.
Definition: event.h:436
#define RTEMS_EVENT_2
This event set constant represents the bit in the event set associated with event 2.
Definition: event.h:126
#define RTEMS_EVENT_23
This event set constant represents the bit in the event set associated with event 23.
Definition: event.h:336
#define RTEMS_EVENT_26
This event set constant represents the bit in the event set associated with event 26.
Definition: event.h:366
#define RTEMS_EVENT_13
This event set constant represents the bit in the event set associated with event 13.
Definition: event.h:236
#define RTEMS_EVENT_6
This event set constant represents the bit in the event set associated with event 6.
Definition: event.h:166
#define RTEMS_EVENT_25
This event set constant represents the bit in the event set associated with event 25.
Definition: event.h:356
#define RTEMS_EVENT_8
This event set constant represents the bit in the event set associated with event 8.
Definition: event.h:186
uint32_t rtems_task_priority
This integer type represents task priorities of the Classic API.
Definition: types.h:257
Objects_Id rtems_id
This type represents RTEMS object identifiers.
Definition: types.h:94
Status_Control
Status codes.
Definition: status.h:111
This header file provides the interfaces of the Atomic Operations.
This header file provides the interfaces of the Operation Status Support.
Definition: tx-thread-queue.h:148
void(* get_properties)(struct TQContext *, TQWorkerKind)
This member provides the get properties handler.
Definition: tx-thread-queue.h:254
Status_Control(* surrender)(struct TQContext *)
This member provides the thread queue surrender handler.
Definition: tx-thread-queue.h:296
TQWait wait
This member defines the enqueue wait behaviour.
Definition: tx-thread-queue.h:159
Status_Control(* convert_status)(Status_Control)
This member provides the status convert handler.
Definition: tx-thread-queue.h:259
volatile bool event_received[TQ_WORKER_COUNT]
When a worker received an event, the corresponding element shall be set to true.
Definition: tx-thread-queue.h:196
rtems_id runner_id
This member contains the runner task identifier.
Definition: tx-thread-queue.h:174
void(* enqueue_prepare)(struct TQContext *)
This member provides the thread queue enqueue prepare handler.
Definition: tx-thread-queue.h:281
volatile bool busy_wait[TQ_WORKER_COUNT]
If this member is true, then the worker shall busy wait on request.
Definition: tx-thread-queue.h:201
void(* enqueue_done)(struct TQContext *)
This member provides the thread queue enqueue done handler.
Definition: tx-thread-queue.h:291
T_scheduler_log_40 scheduler_log
This member provides the scheduler log.
Definition: tx-thread-queue.h:249
rtems_id mutex_id[TQ_MUTEX_COUNT]
This member contains the identifier of priority inheritance mutexes.
Definition: tx-thread-queue.h:244
uint32_t flush_count
This this member contains the count of the least recently flushed threads.
Definition: tx-thread-queue.h:270
uint32_t how_many
This this member specifies how many threads shall be enqueued.
Definition: tx-thread-queue.h:264
volatile bool done[TQ_WORKER_COUNT]
When a worker is done processing its current event set, the corresponding element shall be set to tru...
Definition: tx-thread-queue.h:207
TQEnqueueVariant enqueue_variant
This member defines the enqueue variant.
Definition: tx-thread-queue.h:164
void * thread_queue_object
This member contains the reference to object containing the thread queue under test.
Definition: tx-thread-queue.h:237
TQDeadlock deadlock
This member defines the deadlock enqueue behaviour.
Definition: tx-thread-queue.h:169
rtems_tcb * runner_tcb
This member contains a reference to the runner task control block.
Definition: tx-thread-queue.h:179
Atomic_Uint counter
This member provides the counter used for the worker counters.
Definition: tx-thread-queue.h:212
uint32_t(* flush)(struct TQContext *, uint32_t, bool)
This member provides the thread queue flush handler.
Definition: tx-thread-queue.h:306
jmp_buf before_enqueue
This this member provides a context to jump back to before the enqueue.
Definition: tx-thread-queue.h:276
rtems_id worker_id[TQ_WORKER_COUNT]
This member contains the worker task identifiers.
Definition: tx-thread-queue.h:184
rtems_id thread_queue_id
This member contains the identifier of an object providing the thread queue under test.
Definition: tx-thread-queue.h:231
uint32_t worker_counter[TQ_WORKER_COUNT]
When a worker returned from TQEnqueue() the counter is incremented and stored in this member.
Definition: tx-thread-queue.h:218
TQDiscipline discipline
This member defines the thread queue discipline.
Definition: tx-thread-queue.h:152
Status_Control status[TQ_WORKER_COUNT]
This member contains the last return status of a TQEnqueue() of the corresponding worker.
Definition: tx-thread-queue.h:224
Status_Control(* enqueue)(struct TQContext *, TQWait)
This member provides the thread queue enqueue handler.
Definition: tx-thread-queue.h:286
rtems_tcb * worker_tcb[TQ_WORKER_COUNT]
This member contains references to the worker task control blocks.
Definition: tx-thread-queue.h:190
Definition: tx-thread-queue.h:501
TQMtxProtocol protocol
This member defines the locking protocol.
Definition: tx-thread-queue.h:510
TQContext base
This member contains the base thread queue test context.
Definition: tx-thread-queue.h:505
TQMtxRecursive recursive
This member defines the recursive seize behaviour.
Definition: tx-thread-queue.h:515
TQMtxOwnerCheck owner_check
This member defines the owner check behaviour.
Definition: tx-thread-queue.h:520
rtems_task_priority priority_ceiling
This member defines the priority ceiling of the mutex.
Definition: tx-thread-queue.h:528
Definition: tx-thread-queue.h:449
TQContext base
This member contains the base thread queue test context.
Definition: tx-thread-queue.h:453
uint32_t(* get_count)(struct TQSemContext *)
This member provides the semaphore get count handler.
Definition: tx-thread-queue.h:463
TQSemVariant variant
This member defines the semaphore variant.
Definition: tx-thread-queue.h:458
void(* set_count)(struct TQSemContext *, uint32_t)
This member provides the semaphore set count handler.
Definition: tx-thread-queue.h:468
Definition: test-scheduler.h:81
Definition: test-scheduler.h:158
Definition: thread.h:837
Definition: mutex.h:4
This header file defines the scheduler test support API.
This header file provides the support functions for the validation test cases.