Skip to content

Commit

Permalink
eal/freebsd: fix lock in alarm callback
Browse files Browse the repository at this point in the history
[ upstream commit fc6bdd5248e843ba1300c8d46d43b263b4a69438 ]

The spinlock should unlock when clock_gettime() failed. This patch
fixes it by invoking clock_gettime() before lock.

Fixes: 26021a7 ("eal/bsd: support alarm API")

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Bruce Richardson <bruce.richardson@intel.com>
  • Loading branch information
fengchengwen authored and bluca committed Feb 23, 2023
1 parent 7dbf8ba commit 45ff268
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/librte_eal/freebsd/eal_alarm.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ eal_alarm_callback(void *arg __rte_unused)
struct timespec now;
struct alarm_entry *ap;

rte_spinlock_lock(&alarm_list_lk);
ap = LIST_FIRST(&alarm_list);

if (clock_gettime(CLOCK_TYPE_ID, &now) < 0)
return;

rte_spinlock_lock(&alarm_list_lk);
ap = LIST_FIRST(&alarm_list);

while (ap != NULL && timespec_cmp(&now, &ap->time) >= 0) {
ap->executing = 1;
ap->executing_id = pthread_self();
Expand Down

0 comments on commit 45ff268

Please sign in to comment.