Example 8–3 is an example of a read device interrupt handler.
#include <sys/types.h> #include <sys/param.h> #include <sys/stream.h> buffcall_id_t id; /* hold id val for unbufcall */ dev_rintr(dev) { /* process incoming message ... */ /* allocate new buffer for device */ dev_re_load(dev); } /* * Reload device with a new receive buffer */ dev_re_load(dev) { mblk_t *bp; id = 0; /* begin with no waiting for buffers */ if ((bp = allocb(DEVBLKSZ, BPRI_MED)) == NULL) { cmn_err(CE_WARN,"dev:allocbfailure(size%d)\n", DEVBLKSZ); /* * Allocation failed. Use bufcall to * schedule a call to ourselves. */ id = bufcall(DEVBLKSZ,BPRI_MED,dev_re_load,dev); return; } /* pass buffer to device ... */ }
See Chapter 12, Multithreaded STREAMS for more information on the uses of unbufcall(9F). These references to unbufcall are protected by MT locks.
Because bufcall(9F) can fail, there is still a chance that the device will hang. A better strategy if bufcall(9F) fails is to discard the current input message and resubmit that buffer to the device. Losing input data is preferable to the device hanging.