linuxkpi: Define hrtimer_try_to_cancel()

It is the same as callout_stop(9) but the return values are different.

Reviewed by:	hselasky
Approved by:	hselasky
Differential Revision:	https://reviews.freebsd.org/D38081
This commit is contained in:
Jean-Sébastien Pédron 2023-01-11 02:00:57 +01:00
parent 424f1296bd
commit bb651c77f5
No known key found for this signature in database
GPG Key ID: 39E99761A5FD94CC
2 changed files with 24 additions and 0 deletions

View File

@ -53,6 +53,7 @@ struct hrtimer {
};
#define hrtimer_active(hrtimer) linux_hrtimer_active(hrtimer)
#define hrtimer_try_to_cancel(hrtimer) linux_hrtimer_try_to_cancel(hrtimer)
#define hrtimer_cancel(hrtimer) linux_hrtimer_cancel(hrtimer)
#define hrtimer_init(hrtimer, clock, mode) do { \
@ -79,6 +80,7 @@ struct hrtimer {
} while (0)
bool linux_hrtimer_active(struct hrtimer *);
int linux_hrtimer_try_to_cancel(struct hrtimer *);
int linux_hrtimer_cancel(struct hrtimer *);
void linux_hrtimer_init(struct hrtimer *);
void linux_hrtimer_set_expires(struct hrtimer *, ktime_t);

View File

@ -65,6 +65,28 @@ linux_hrtimer_active(struct hrtimer *hrtimer)
return (ret);
}
/*
* Try to cancel active hrtimer.
* Return 1 if timer was active and cancellation succeeded, 0 if timer was
* inactive, or -1 if the timer is being serviced and can't be cancelled.
*/
int
linux_hrtimer_try_to_cancel(struct hrtimer *hrtimer)
{
int ret;
mtx_lock(&hrtimer->mtx);
ret = callout_stop(&hrtimer->callout);
mtx_unlock(&hrtimer->mtx);
if (ret > 0) {
return (1);
} else if (ret < 0) {
return (0);
} else {
return (-1);
}
}
/*
* Cancel active hrtimer.
* Return 1 if timer was active and cancellation succeeded, or 0 otherwise.