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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

This notification type is a little scary! You could have a whole slew of threads created<br />

if the timer fires often enough and, if there are higher priority threads waiting to run,<br />

this could chew up all available resources on the system! Use <strong>with</strong> caution!<br />

General tricks for notification<br />

There are some convenience macros in to make filling in the<br />

notification structures easier (see the entry for sigevent in the <strong>Neutrino</strong> Library<br />

Reference):<br />

Pulse notification<br />

SIGEV_SIGNAL_INIT (eventp, signo)<br />

Fill eventp <strong>with</strong> SIGEV_SIGNAL, and the appropriate signal number signo.<br />

SIGEV_SIGNAL_CODE_INIT (eventp, signo, value, code)<br />

Fill eventp <strong>with</strong> SIGEV_SIGNAL_CODE, the signal number signo, as well as the<br />

value and code.<br />

SIGEV_SIGNAL_THREAD_INIT (eventp, signo, value, code)<br />

Fill eventp <strong>with</strong> SIGEV_SIGNAL_THREAD, the signal number signo, as well as<br />

the value and code.<br />

SIGEV_PULSE_INIT (eventp, coid, priority, code, value)<br />

Fill eventp <strong>with</strong> SIGEV_SIGNAL_PULSE, the connection to the channel in coid<br />

and a priority, code, and value. Note that there is a special value for priority of<br />

SIGEV_PULSE_PRIO_INHERIT that causes the receiving thread to run at the<br />

process’s initial priority.<br />

SIGEV_UNBLOCK_INIT (eventp)<br />

Fill eventp <strong>with</strong> SIGEV_UNBLOCK.<br />

SIGEV_INTR_INIT (eventp)<br />

Fill eventp <strong>with</strong> SIGEV_INTR.<br />

SIGEV_THREAD_INIT (eventp, func, val, attributes)<br />

Fill eventp <strong>with</strong> the thread function (func) and the attributes structure<br />

(attributes). The value in val is passed to the function in func when the thread is<br />

executed.<br />

Suppose you’re designing a server that spent most of its life RECEIVE blocked,<br />

waiting for a message. Wouldn’t it be ideal to receive a special message, one that told<br />

you that the time you had been waiting for finally arrived?<br />

This scenario is exactly where you should use pulses as the notification scheme. In the<br />

“Using timers” section below, I’ll show you some sample code that can be used to get<br />

periodic pulse messages.<br />

April 30, 2009 Chapter 3 • Clocks, Timers, and <strong>Getting</strong> a Kick Every So Often 145

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

Saved successfully!

Ooh no, something went wrong!