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.

Clocks and timers<br />

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

Notification schemes<br />

The implementation in the kernel is still based on the same principle as the delay timer<br />

that we used in our first example. The kernel takes the absolute time (if you specified<br />

it that way) and stores it. In the clock ISR, the stored time is compared against the<br />

time of day in the usual manner.<br />

However, instead of your thread being removed from the running queue when you call<br />

the kernel, your thread continues to run. When the time of day reaches the stored time,<br />

the kernel notifies your thread that the designated time has been reached.<br />

How do you receive a timeout notification? With the delay timer, you received<br />

notification by virtue of being made READY again.<br />

With periodic and one-shot timers, you have a choice:<br />

• send a pulse<br />

• send a signal<br />

• create a thread<br />

How to fill in the struct sigevent<br />

We’ve talked about pulses in the Message Passing chapter; signals are a standard<br />

UNIX-style mechanism, and we’ll see the thread creation notification type shortly.<br />

Let’s take a quick look at how you fill in the struct sigevent structure.<br />

Regardless of the notification scheme you choose, you’ll need to fill in a struct<br />

sigevent structure:<br />

struct sigevent {<br />

int<br />

union {<br />

int<br />

int<br />

int<br />

void<br />

};<br />

union sigval<br />

sigev_notify;<br />

sigev_signo;<br />

sigev_coid;<br />

sigev_id;<br />

(*sigev_notify_function) (union sigval);<br />

sigev_value;<br />

};<br />

union {<br />

struct {<br />

short sigev_code;<br />

short sigev_priority;<br />

};<br />

pthread_attr_t *sigev_notify_attributes;<br />

};<br />

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

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

Saved successfully!

Ooh no, something went wrong!