Queues
Memory and Low-level Functions
5-15
5.3 Queues
The QUE module provides a set of functions to manage a list of QUE
elements. Though elements can be inserted or deleted anywhere within the
list, the QUE module is most often used to implement a FIFO list—elements
are inserted at the tail of the list and removed from the head of the list. QUE
elements can be any structure whose first field is of type QUE_Elem. In
Example 5-15, QUE_Elem is used by the QUE module to enqueue the
structure while the remaining fields contain the actual data to be enqueued.
QUE_create and QUE_delete are used to create and delete queues,
respectively. Since QUE queues are implemented as linked lists, queues
have no maximum size. This is also shown in Example 5-15.
Example 5-15.
Managing QUE Elements Using Queues
5.3.1
Atomic QUE Functions
QUE_put and QUE_get are used to atomically insert an element at the tail of
the queue or remove an element from the head of the queue. These functions
are atomic in that elements are inserted and removed with interrupts
disabled. Therefore, multiple threads can safely use these two functions to
modify a queue without any external synchronization.
QUE_get atomically removes and returns the element from the head of the
queue, whereas, QUE_put atomically inserts the element at the tail of the
queue. In both functions, the queue element has type Ptr to avoid
unnecessary type casting as shown in Example 5-16.
Example 5-16.
Inserting into a Queue Atomically
typedef struct QUE_Elem {
struct QUE_Elem *next;
struct QUE_Elem *prev;
} QUE_Elem;
typedef struct MsgObj {
QUE_Elem elem;
Char val;
} MsgObj;
QUE_Handle QUE_create(attrs)
QUE_Attrs *attrs;
Void QUE_delete(queue)
QUE_Handle queue;
Ptr QUE_get(queue)
QUE_Handle queue;
Ptr QUE_put(queue, elem)
QUE_Handle queue;
Ptr elem;
Summary of Contents for TMS320 Series
Page 1: ...TMS320 DSP BIOS v5 40 User s Guide Literature Number SPRU423G April 2009 ...
Page 16: ...xvi ...
Page 152: ...Tasks 4 48 Figure 4 12 Trace from Example 4 7 ...
Page 168: ...Semaphores 4 64 Figure 4 14 Trace Results from Example 4 11 ...
Page 202: ...5 20 ...
Page 287: ...Index 9 Index Void 1 11 W words data memory 3 15 of code 1 5 wrapper function 2 29 ...
Page 288: ...Index 10 Index ...