On Dec 16, 2008, at 6:47 PM, Mike Abbott wrote:
Hmm. Actually I think when I was writing that code I noticed the same thing and tried to fix it with:
/* there can be multiple events for a single io. call the callback only once if that happens. */ if (io->refcount == 2 && io->io.callback != NULL) io->io.callback(io->io.context);
When there are near-duplicates in the returned events -- that is,
two or more entries in the events array having the same udata but
different fflags -- the refcount==2 check actually prevents the
callback from being called at all (assuming Apple's patch to this
area has not been applied, and the assert is removed). The first
loop increments the refcount twice (or more), from 1 to 3 (or
higher). Then the second loop skips the callback entirely because
the refcount does not equal 2. The callback is not even called once.
But it decreases the refcount every time. So if refcount starts at 3,
the second loop skips the first callback -> decreases refcount to 2 ->
calls callback -> decreases refcount to 1.