aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Sébastien Pédron <dumbbell@FreeBSD.org>2023-01-11 01:00:57 +0000
committerJean-Sébastien Pédron <dumbbell@FreeBSD.org>2023-02-16 11:55:11 +0000
commitec8401ffaeb399f8d02db237e6c2390c1e3f7bf5 (patch)
treedf1bab36537dd00261df68abe03d9a52a7ac7fd3
parente50dd7e3bf1cdddcb5bd3b0fa1a57843cb8a30a1 (diff)
downloadsrc-ec8401ffaeb399f8d02db237e6c2390c1e3f7bf5.tar.gz
src-ec8401ffaeb399f8d02db237e6c2390c1e3f7bf5.zip
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 (cherry picked from commit bb651c77f5f71a38dd90b2eee214e7a2224421a7)
-rw-r--r--sys/compat/linuxkpi/common/include/linux/hrtimer.h2
-rw-r--r--sys/compat/linuxkpi/common/src/linux_hrtimer.c22
2 files changed, 24 insertions, 0 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/hrtimer.h b/sys/compat/linuxkpi/common/include/linux/hrtimer.h
index 23e707d906b4..4a63db80cc12 100644
--- a/sys/compat/linuxkpi/common/include/linux/hrtimer.h
+++ b/sys/compat/linuxkpi/common/include/linux/hrtimer.h
@@ -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);
diff --git a/sys/compat/linuxkpi/common/src/linux_hrtimer.c b/sys/compat/linuxkpi/common/src/linux_hrtimer.c
index a56485512a14..5d9b376f9561 100644
--- a/sys/compat/linuxkpi/common/src/linux_hrtimer.c
+++ b/sys/compat/linuxkpi/common/src/linux_hrtimer.c
@@ -66,6 +66,28 @@ linux_hrtimer_active(struct hrtimer *hrtimer)
}
/*
+ * 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.
*/