Pipes in RTOS
Pipes in RTOS
Pipes
Pipe – Intro
• A pipe is an RTOS object that provide simple communication channel used for
unstructured data communication among tasks
• Pipes are also used for synchronization among multiple tasks
• Pipes are unidirectional - Data flows in only one direction
• Two descriptors are returned when a pipe gets created - One for reading and
one for writing
• Data is read from the pipe in FIFO order
• The reader gets blocked when the pipe is empty. Similarly the writer gets
blocked when the pipe is full
• Typically, pipes are used between a data-producing task and a data-consuming
task
• There could be multiple writers and multiple readers for a pipe
• Function calls for pipes include
• Create
• Open
• Close
• Read from the pipe
• Write to the pipe
Pipe – Intro
• A pipe provides a simple data flow facility so that the reader becomes blocked
when the pipe is empty, and the writer becomes blocked when the pipe is full.
• It is also permissible to have several writers for the pipe with multiple readers
on it
• Note that a pipe is conceptually similar to a message queue but with significant
differences
• Unlike a message queue, a pipe does not store multiple messages
• The data that it stores is not structured, but consists of a stream of bytes.
• Data in a pipe cannot be prioritized. The data flow is strictly first-in, first-out
FIFO Pipes support the powerful select operation, and message queues do not.
Pipe – Intro
• Pipes can be dynamically created or destroyed
• The kernel creates and maintains pipe-specific information in an internal data structure called a pipe
control block
• The structure of the pipe control block varies from one implementation to another
• In its general form, a pipe control block contains the following:
• kernel-allocated data buffer for the pipe’s input and output operation
• The size of this buffer is maintained in the control block and is fixed when the pipe is created
• The current data byte count
• current input and output position indicators
• The kernel creates two descriptors that are unique within the system I/O space and returns these
descriptors to the creating task. These descriptors identify each end of the pipe uniquely.
• Two task-waiting lists are associated with each pipe
• One waiting list keep track of tasks that are waiting to write into the pipe while it is full; The other keeps
track of tasks that are waiting to read from the pipe while it is empty.
Pipe - Status
A pipe has a limited number of states associated with it from the time of its creation
to its termination. Each state corresponds to the data transfer state between the
reader and the writer of the pipe
Named and Unnamed pipes
A kernel typically supports two kinds of pipe objects:
Named pipes and
Unnamed pipes
The unnamed pipe does not have a name and does not appear
in the file system. It must be referenced by the descriptors that
the kernel returns when the pipe is created
Typical pipe operations
• Create and destroy a pipe,
• read from or write to a pipe,
• issue control commands on the pipe, and
• select on a pipe.
Pipe – Create, Open & Close calls
• Calls for creation of a pipe always creates a unnamed pipe. This
operation returns two descriptors to the calling task one for reading
and the other for writing
• The write operation appends new data to the existing byte stream in the pipe
• The calling task specifies the amount of data to write into the pipe
• The task may choose to block waiting for additional buffer space to become free when the
amount to write exceeds the available space.