Skip to content

Commit

Permalink
tmr: add tmr_start_dbg (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers authored May 27, 2022
1 parent 78ec61f commit b2b73ea
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
19 changes: 18 additions & 1 deletion include/re_tmr.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ struct tmr {
tmr_h *th; /**< Timeout handler */
void *arg; /**< Handler argument */
uint64_t jfs; /**< Jiffies for timeout */
char *file;
int line;
};


Expand All @@ -29,7 +31,22 @@ void tmr_debug(void);
int tmr_status(struct re_printf *pf, void *unused);

void tmr_init(struct tmr *tmr);
void tmr_start(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg);
void tmr_start_dbg(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg,
char *file, int line);

/**
* @def tmr_start(tmr, delay, th, arg)
*
* Start a timer
*
* @param tmr Timer to start
* @param delay Timer delay in [ms]
* @param th Timeout handler
* @param arg Handler argument
*/
#define tmr_start(tmr, delay, th, arg) \
tmr_start_dbg(tmr, delay, th, arg, __FILE__, __LINE__)

void tmr_cancel(struct tmr *tmr);
uint64_t tmr_get_expire(const struct tmr *tmr);

Expand Down
23 changes: 9 additions & 14 deletions src/tmr/tmr.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@ int tmr_status(struct re_printf *pf, void *unused)

for (le = tmrl->head; le; le = le->next) {
const struct tmr *tmr = le->data;

err |= re_hprintf(pf, " %p: th=%p expire=%llums\n",
err |= re_hprintf(pf, " %p: th=%p expire=%llums file=%s:%d\n",
tmr, tmr->th,
(unsigned long long)tmr_get_expire(tmr));
(unsigned long long)tmr_get_expire(tmr),
tmr->file, tmr->line);
}

if (n > 100)
Expand Down Expand Up @@ -248,15 +248,8 @@ void tmr_init(struct tmr *tmr)
}


/**
* Start a timer
*
* @param tmr Timer to start
* @param delay Timer delay in [ms]
* @param th Timeout handler
* @param arg Handler argument
*/
void tmr_start(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg)
void tmr_start_dbg(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg,
char *file, int line)
{
struct list *tmrl = tmrl_get();
struct le *le;
Expand All @@ -268,8 +261,10 @@ void tmr_start(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg)
list_unlink(&tmr->le);
}

tmr->th = th;
tmr->arg = arg;
tmr->th = th;
tmr->arg = arg;
tmr->file = file;
tmr->line = line;

if (!th)
return;
Expand Down

0 comments on commit b2b73ea

Please sign in to comment.