tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Let callout_reset return if it reschedules a pending callout



Hi,

This proposal lets callout_reset and callout_schedule return true if
it reschedules a pending callout and return false otherwise.

The feature is useful when you have a reference to an object that is
passed to a callout. In this case you need to take care of a
reference leak on callout_reset (and other APIs); it silently
reschedules (IOW cancels) a pending callout and leaks a reference.
Unfortunately callout_reset doesn't tell us the reschedule.

To avoid the leak with the current APIs of callout, we have to do
something like this:

  if (callout_pending(&obj->ch)) {
    expired = callout_stop(&obj->ch);
    if (!expired)
      obj_unref(obj);
  }
  obj_ref(obj);
  callout_reset(&obj->ch);

callout_pending is required to exclude the case that the callout has
never been scheduled because callout_stop just checks CALLOUT_FIRED.

The proposal makes the code simple like this:

  obj_ref(obj);
  canceled = callout_reset(&obj->ch);
  if (canceled)
    obj_unref(obj);

This is a patch (quite simple):
  http://www.netbsd.org/~ozaki-r/callout_reset.diff

Note that this proposal changes API/ABI however we don't need to
tweak existing callers of callout_reset/callout_schedule because
it doesn't break the original usage.

Any comments?

Thanks,
  ozaki-r


Home | Main Index | Thread Index | Old Index