Download Core Networking Stack User's Guide:

Transcript
is a read operation; if it's a blocking read, the function call may not return until
there is data to read.
• Locking resources.
If the resource is already locked, can it potentially be locked for a long period of
time, blocking the callback function while the driver waits to acquire the lock?
Does your hardware require a service that can take a long period of time, such as
loading the firmware?
Block Op
If the duration of the blocking scenario is known and within a few seconds or less,
you can use the blockop services. Essentially this offloads an operation that may take
some time to the io-pkt main thread (which is typically idle). Note that blockop is
a shared service, and may have multiple operations scheduled. This is meant for
occasional time-consuming operations (such as a firmware upload that occurs once),
but not indefinite or long-term operations and not repetitive operations. It's a
convenience service that handles the complicated management of the stack context
pseudo-thread handling. As it performs these kinds of operations, it must be called
from within the stack context. The callback function however isn't called from the
stack context and shouldn't perform any operations that require the stack context or
buffer management.
The example below is taken from the PPP data link shutdown processing. In this case,
the close() function for the serial port resource manager takes an unusually long, but
predictable, amount of time to reply the the message blocking the close() function.
Since this is called in the stack context, it blocks other io-pkt operations until the
close() returns. This code moves the execution of the close() into the main io-pkt
thread, and pseudo-thread switches to other operations until the callback function
returns. The qnxppp_ttydetach() function pseudo-thread switches at the
blockop_dispatch() and resumes from the same point once the
qnxppp_tty_close_blockop() function returns.
#include <blockop.h>
struct ppp_close_blockop {
int qnxsc_pppfdrd;
int qnxsc_pppfdrd2;
int qnxsc_pppfdwr;
}
void qnxppp_tty_close_blockop(void *arg);
....
void qnxppp_tty_close_blockop(void *arg)
{
struct ppp_close_blockop *pcb = arg;
if(pcb->qnxsc_pppfdrd != -1)
close(pcb->qnxsc_pppfdrd);
if(pcb->qnxsc_pppfdrd2 != -1)
close(pcb->qnxsc_pppfdrd2);
if(pcb->qnxsc_pppfdwr != -1)
close(pcb->qnxsc_pppfdwr);
}
Copyright © 2014, QNX Software Systems Limited
111