Hi adrian.
Your recent cbdataUnlock additions in modio looks wrongly placed.
1. The unlock and callback should most likely be performed by the
store*IOCallback() function, not at individual places in the code.
2. The unlock should ONLY be performed after the data has been used,
i.e. when the pointer is forgotten by the locking code. This is after
the pointer has been cleared in the structure and the callback called,
not before the callback.
3. callbacks should be protected by cbdataValid checks to detect aborted
calls.
Typical cbdata flow:
When the callback is registered
assert(struct->callback == NULL); /* only space for one callback */
struct->callback = callback;
cbdataLock(their_data)
struct->callback_data = their_data;
And when the callback is called
callback = struct->callback;
their_data = struct->callback_data;
struct->callback = NULL;
struct->callback_data = NULL;
if (cbdataValid(their_data))
callback(parameters, ... , their_data);
else /* if aborts not expected nor handled gracefully here */
alert that the callback failed because the caller has gone away
The caller is responsible for calling cbdataAdd when creating the
structure used in callbacks, and to call cbdataFree when it is no longer
used.
Similar, if a callback is registered when your structure is being freed,
then it is your responsibility to notify the callback somehow, or if
calling the callback isn't appropriate alert that something has gone
wrong and only unlock the data.
/Henrik
Received on Fri Apr 21 2000 - 16:57:26 MDT
This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:12:23 MST