26.02.2014 Views

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

Getting Started with QNX Neutrino - QNX Software Systems

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

© 2009, <strong>QNX</strong> <strong>Software</strong> <strong>Systems</strong> GmbH & Co. KG. Pulses<br />

Function Send buffer Receive buffer<br />

MsgSendv() IOV IOV<br />

MsgSendvnc() IOV IOV<br />

Implementation<br />

By “linear,” I mean a single buffer of type void * is passed, along <strong>with</strong> its length.<br />

The easy way to remember this is that the “v” stands for “vector,” and is in the same<br />

place as the appropriate parameter — first or second, referring to “send” or “receive,”<br />

respectively.<br />

Hmmm. . . looks like the MsgSendsv() and MsgSendsvnc() functions are identical,<br />

doesn’t it? Well, yes, as far as their parameters go, they indeed are. The difference lies<br />

in whether or not they are cancellation points. The “nc” versions are not cancellation<br />

points, whereas the non-“nc” versions are. (For more information about cancellation<br />

points and cancelability in general, please consult the <strong>Neutrino</strong> Library Reference,<br />

under pthread_cancel().)<br />

You’ve probably already suspected that all the variants of the MsgRead(),<br />

MsgReceive(), MsgSend(), and MsgWrite() functions are closely related. (The only<br />

exception is MsgReceivePulse() — we’ll look at this one shortly.)<br />

Which ones should you use? Well, that’s a bit of a philosophical debate. My own<br />

personal preference is to mix and match.<br />

If I’m sending or receiving only one-part messages, why bother <strong>with</strong> the complexity of<br />

setting up IOVs? The tiny amount of CPU overhead in setting them up is basically the<br />

same regardless of whether you set it up yourself or let the kernel/library do it. The<br />

single-part message approach saves the kernel from having to do address space<br />

manipulations and is a little bit faster.<br />

Should you use the IOV functions? Absolutely! Use them any time you find yourself<br />

dealing <strong>with</strong> multipart messages. Never copy the data when you can use a multipart<br />

message transfer <strong>with</strong> only a few lines of code. This keeps the system screaming along<br />

by minimizing the number of times data gets copied around the system; passing the<br />

pointers is much faster than copying the data into a new buffer.<br />

Pulses<br />

All the messaging we’ve talked about so far blocks the client. It’s nap time for the<br />

client as soon as it calls MsgSend(). The client sleeps until the server gets around to<br />

replying.<br />

However, there are instances where the sender of a message can’t afford to block.<br />

We’ll look at some examples in the Interrupts and Clocks, Timers, and <strong>Getting</strong> a Kick<br />

Every So Often chapters, but for now we should understand the concept.<br />

The mechanism that implements a non-blocking send is called a pulse. A pulse is a<br />

tiny message that:<br />

April 30, 2009 Chapter 2 • Message Passing 113

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!