Skip to content

Commit

Permalink
tmr: rename lock to list lock and improve comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Jan 12, 2024
1 parent f989f45 commit d47f72b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/re_tmr.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct tmrl;
struct tmr {
struct le le; /**< Linked list element */
RE_ATOMIC bool active; /**< Timer is active */
mtx_t *lock; /**< Mutex lock */
mtx_t *llock; /**< List Mutex lock */
tmr_h *th; /**< Timeout handler */
void *arg; /**< Handler argument */
uint64_t jfs; /**< Jiffies for timeout */
Expand Down
11 changes: 6 additions & 5 deletions src/tmr/tmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,16 @@ static void tmr_startcont_dbg(struct tmr *tmr, uint64_t delay, bool syncnow,
if (!tmr || !tmrl)
return;

/* Prevent multiple cancel race conditions */
if (!re_atomic_acq(&tmr->active) && !th)
return;

re_atomic_rls_set(&tmr->active, false);

if (!tmr->lock || !tmr->le.list)
lock = tmrl->lock;
if (!tmr->llock || !tmr->le.list)
lock = tmrl->lock; /* use current list lock */
else
lock = tmr->lock; /* use old lock for unlinking */
lock = tmr->llock; /* use old list lock for unlinking */

mtx_lock(lock);

Expand All @@ -418,10 +419,10 @@ static void tmr_startcont_dbg(struct tmr *tmr, uint64_t delay, bool syncnow,
tmr->arg = arg;
tmr->file = file;
tmr->line = line;
tmr->lock = tmrl->lock;
tmr->llock = tmrl->lock;

if (!th) {
tmr->lock = NULL;
tmr->llock = NULL;
mtx_unlock(lock);
return;
}
Expand Down

0 comments on commit d47f72b

Please sign in to comment.