hello,
not exactly a ddk question, but close enough.
i’m trying to write a resource manager for a device (say /dev/foo) and
i’d like it to support both blocking and non-blocking i/o.
blocking i/o means that a read() from the /dev/foo should block unless
/dev/foo has data to return, or, /dev/foo was open()ed with o_nonblock.
consider the following meta code:
int
my_io_read(resmgr_context_t *ctp, io_read_t *msg, RESMGR_OCB_T *ocb)
{
int status, nonblock;
status = io_read_verify(ctp, msg, ocb, &nonblock);
if (status != EOK)
return (status);
if ((msg->i.xtype & _IO_XTYPE_MASK) != _IO_XTYPE_NONE)
return (ENOSYS);
…
if (!have_data_for_client) {
if (nonblock)
return (EWOULDBLOCK);
/* XXX block until we have data to return */
}
…
}
now, how could i block in my_io_read()?
obviously, my first idea to simply put pthread_conf_wait() to block
calling thread. however, after re-reading available resource manager
documentation, i realized that io_read (and other io_xxx callbacks)
apparently called with iofunc_attr_t locked. without knowing more about
resource manager internals, i assume that i’m allowed to call
iofunc_attr_unlock() in my_io_read(), right?
while searching for the answer, i found out that one can remember
sender’s id etc. from io_read msg/ocb and return _RESMGR_NOREPLY from
io_read. later, when data is available, one can send a reply using
previously stored information. is this the only solution to the problem?
thanks,
max