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.

tp1.c<br />

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

contextfree (THREAD_POOL_PARAM_T *param)<br />

{<br />

tag ("contextfree"); printf ("param %p\n", param);<br />

}<br />

void<br />

unblockfunc (THREAD_POOL_PARAM_T *ctp)<br />

{<br />

tag ("unblockfunc"); printf ("ctp %p\n", ctp);<br />

}<br />

int<br />

handlerfunc (THREAD_POOL_PARAM_T *ctp)<br />

{<br />

static int i = 0;<br />

tag ("handlerfunc"); printf ("ctp %p\n", ctp);<br />

if (i++ > 15) {<br />

tag ("handlerfunc"); printf ("exceeded 15 operations, return 0\n");<br />

return (0);<br />

}<br />

tag ("handlerfunc"); printf ("sleep (%d)\n", pthread_self () * 25);<br />

sleep (pthread_self () * 25);<br />

tag ("handlerfunc"); printf ("done sleep\n");<br />

/*<br />

i = 0;<br />

if (i++ & 1) {<br />

tag ("handlerfunc"); printf ("returning 0\n");<br />

return (0);<br />

} else {<br />

*/<br />

tag ("handlerfunc"); printf ("returning 0x%08X\n", 0x30000000 + pthread_self ());<br />

return (0x30000000 + pthread_self ());<br />

/*<br />

}<br />

*/<br />

}<br />

main ()<br />

{<br />

thread_pool_attr_t tp_attr;<br />

void *tpp;<br />

memset (&tp_attr, 0, sizeof (tp_attr));<br />

tp_attr.handle = (void *) 0x12345678; // passed to contextalloc<br />

tp_attr.block_func = blockfunc;<br />

tp_attr.unblock_func = unblockfunc;<br />

tp_attr.context_alloc = contextalloc;<br />

tp_attr.context_free = contextfree;<br />

tp_attr.handler_func = handlerfunc;<br />

tp_attr.lo_water = 3;<br />

tp_attr.hi_water = 7;<br />

tp_attr.increment = 2;<br />

tp_attr.maximum = 10;<br />

tpp = thread_pool_create (&tp_attr, POOL_FLAG_USE_SELF);<br />

if (tpp == NULL) {<br />

fprintf (stderr,<br />

"%s: can’t thread_pool_create, errno %s\n",<br />

progname, strerror (errno));<br />

322 Appendix: C • Sample Programs April 30, 2009

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

Saved successfully!

Ooh no, something went wrong!