Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/brpc/ubshm/timer/timer_mgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,10 @@ int UbrTimerDel(UbrTimerId* slot) {
} // ==1: dispatched, OnFire (owned==false)
// releases it
ReleaseRef(task); // owner
return 0; // the callback is guaranteed never to run: the caller
// consumes the timer/callback reference
return 0; // This call won the slot competition. For a one-shot timer,
// the callback will not run. For a periodic timer, future
// rearming is stopped, but an already dispatched or running
// callback may still complete.
}

void UbrTimerDelAndWait(UbrTimerId* slot) {
Expand Down
24 changes: 14 additions & 10 deletions src/brpc/ubshm/timer/timer_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,20 @@ RETURN_CODE UbrTimerStart(UbrTimerId* slot, uint64_t delay_us,
void* arg,
UbrTimerBackoffFn backoff = nullptr);

// Non-blocking delete, safe from inside the timer callback itself. Does
// not wait for a running callback and does not protect `arg' on its own.
// Returns 0 when the call won the slot competition: a one-shot callback
// is guaranteed never to run, and the caller consumes any per-task
// resources it tracks for this timer (ownership of them transfers to the
// caller); for a periodic timer an already-started callback is not
// interrupted. Returns 1 when the callback has been dispatched (it
// consumes those resources itself on every exit) or its fate is still
// being settled by the scheduler -- the caller must not consume anything
// then.
// Non-blocking delete, safe to call from inside the timer callback itself.
// This function does not wait for an already running callback and does not
// protect resources reachable from `arg` on its own.
//
// Returns 0 when this call wins the handle-slot competition.
// - For a one-shot timer, the callback will not run.
// - For a periodic timer, future rearming is stopped, but an already
// dispatched or running callback may still execute once more. Callers
// must not reclaim resources reachable from `arg` based on this return
// alone; use UbrTimerDelAndWait when teardown needs to wait for callbacks.
//
// Returns 1 when this caller did not acquire timer ownership. The callback,
// another deleter, or the scheduling path is responsible for settling the
// timer resources, so this caller must not reclaim them.
int UbrTimerDel(UbrTimerId* slot);

// Delete and wait until a possibly running callback finished, so the
Expand Down