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. Advanced topics<br />

IOFUNC_OCB_T *<br />

my_ocb_calloc (resmgr_context_t *ctp, IOFUNC_ATTR_T *attr);<br />

void<br />

my_ocb_free (IOFUNC_OCB_T *ocb);<br />

This means that the my_ocb_calloc() function gets passed both the internal resource<br />

manager context and the attributes structure. The function is responsible for returning<br />

an initialized OCB. The my_ocb_free() function gets passed the OCB and is<br />

responsible for releasing the storage for it.<br />

OCB monitor<br />

More efficient allocation<br />

It’s important to realize that the OCB may be allocated by functions other than the<br />

normal io_open() handler — for example, the memory manager may allocate an OCB.<br />

The impact of this is that your OCB allocating function must be able to initialize the<br />

OCB <strong>with</strong> the attr argument.<br />

There are two interesting uses for these two functions (that have nothing to do <strong>with</strong><br />

extending the OCB):<br />

• OCB allocation/deallocation monitor<br />

• more efficient allocation/deallocation<br />

In this case, you can simply “tie in” to the allocator/deallocator and monitor the usage<br />

of the OCBs (for example, you may wish to limit the total number of OCBs<br />

outstanding at any given time). This may prove to be a good idea if you’re not taking<br />

over the io_open() outcall, and yet still need to intercept the creation of (and possibly<br />

deletion of) OCBs.<br />

Another use for overriding the library’s built-in OCB allocator/deallocator is that you<br />

may wish to keep the OCBs on a free list, instead of the library’s calloc() and free()<br />

functions. If you’re allocating and deallocating OCBs at a high rate, this may prove to<br />

be more efficient.<br />

Extending the attributes structure<br />

You may wish to extend the attributes structure in cases where you need to store<br />

additional device information. Since the attributes structure is associated on a<br />

“per-device” basis, this means that any extra information you store there will be<br />

accessible to all OCBs that reference that device (since the OCB contains a pointer to<br />

the attributes structure). Often things like serial baud rate, etc. are stored in extended<br />

attributes structures.<br />

Extending the attributes structure is much simpler than dealing <strong>with</strong> extended OCBs,<br />

simply because attributes structures are allocated and deallocated by your code<br />

anyway.<br />

April 30, 2009 Chapter 5 • Resource Managers 271

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

Saved successfully!

Ooh no, something went wrong!