Sistema propulsor
5.7. Sistema de navegación
sem_post()
Frees the semaphore for general use and returns the handle immediately.
Prototype int sem_post(sem_t *sem);
Parameters
Return Values
sem_t *sem Pointer to a semaphore structure.
Success: 0
Failure: -1 with errno set to:
EACCES if the "sem" is not in user space.
EINVAL if the "sem" is improperly aligned.
CAUTION
Use errno with caution as it is a global variable shared by other threads.
MULTITASKING
Pipes
Pipes
A pipe is a bidirectional communication channel connecting two tasks. One task communicates with another by writing to and reading from the pipe that connects them. A pipe behaves much like an RS-232 cable connecting two terminals: Data written into the pipe at one end are read out at the other end. Both ends can be read from and written to simultaneously (full-duplex operation). Pipes provide a clearly defined communication mechanism that avoids hidden interactions between tasks.Pipes are dynamic. They are created when opened and deleted when closed.
They do not remain intact through terminal resets or power cycles. Any data in a pipe are lost after a terminal reset or power cycle. When the application restarts and reopens the pipe, the pipe is recreated. Two types of pipes are available:
• Character
• Message
A character pipe treats the data going through it as individual bytes. When a task writes a buffer to the pipe, the operating system writes one byte at a time into the pipe, and reads from the pipe in the same way. At the application level, the task can (and should for efficiency) read and write buffers of several characters at a time.
A message pipe treats each write buffer as a single entity; each item in the pipe is a complete message. When a task writes a buffer, the operating system writes the entire buffer at once. When a task reads from the pipe, an entire message is removed from the pipe and copied to the read buffer. If the read buffer is not large enough to hold the message, the operating system transfers as much of the message as possible; the rest is discarded. One feature of the message pipe is that the size of the message is preserved from the writer to the reader.
The number of pipes allocated by the operating system is determined by the environment variable *PIPE in the CONFIG.SYS file (see System Configuration File). By default, if *PIPE is not set or is set to an invalid value, the number of pipes allocated is at maximum 256.
Always check result codes to detect insufficient buffers. It is well worth intensive planning and testing to verify that the design has adequate buffers. Leaving *B set to the maximum default usually provides sufficient buffers, but the system can still consume the maximum buffers if, for example, a task is using all buffers to write a very long receipt. This may take a few milliseconds, but consumes many buffers.
Pipes
Pipe Interface The application interface to pipes is a subset of the standard file system interface.
It supports the standard open(), close(), read(), and write() function calls.
There are also pipe-specific function calls, that allow configuration of the type of pipe needed and connect one pipe to another.
Configure the Pipe
Prototype int status = pipe_init_msg (int pipehandle, int maxmessages);
int status = pipe_init_char (int pipehandle, int maxcharacters);
Parameters
Return Values
maxmessages Specifies the maximum number of write() operations that can be made to the message-type pipe at one time (that is, before any of the buffered messages are read).
maxcharacters For character-type pipes, determines the maximum number of characters that can be written to the pipe before any characters are read.
Success: 0
Failure: –1, with errno set to EBADF: The pipe is not open.
MULTITASKING
Pipes
Pipe Function Calls
This section presents the pipe-specific function calls.
close()
close()
Closes open pipe handle.
Prototype int close(handle);
Parameters
Return Values Always returns 0.
Action If handle is not found in the list of open pipes, only return 0; if found, mark this pipe closed. Any data in the FIFOs remains in the FIFOs after close(); it is not purged.
handle Handle of pipe to close.
MULTITASKING
open()
open()
Allocates a pipe control block and assigns the specified name. Only the first eight characters of the name are significant. The name is useful to other tasks that need to connect to this pipe. For an example, see the section on get_owner().
Sometimes the name is not important. In this case, the application can utilize an anonymous pipe by opening a pipe with the special name "P:" as the first parameter.
Prototype handle = open(const char * pipename, int opentype);
Parameters
Return Values
pipename There are two ways to identify this parameter:
Statically defined: In the form “P:name,” where name is the name (an ASCII string of up to 7 bytes) that uniquely identifies the pipe.
Dynamically defined: Set to “P:” with no numeric suffix. In this case the OS assigns an unused pipe number. This is sometimes referred to as an anonymous pipe.
The pipename parameter is not case sensitive. Only the first eight characters of the name (not counting P:) are significant.
opentype Currently ignored.
NOTE Pipe names must be unique. Use of P:PIPE is not recommended as the get_owner() call only detects the first use. Most pipes can be opened
anonymously. Server tasks (for example, a print server) are the primary users of this feature.
Success: The handle of the created pipe.
Failure: –1 with errno set to ENOMEM: Not enough memory to allocate needed data structures.
–1 with errno set to EACCES: The pipename parameter is not readable.