kernel/mrsas: Fix a double assignment.
[dragonfly.git] / sys / dev / drm / linux_hrtimer.c
blobeb75689205a81546ebb73bf5216e2ddfd7fbbf07
1 /*
2 * Copyright (c) 2017 François Tigeot
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice unmodified, this list of conditions, and the following
10 * disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include <linux/hrtimer.h>
28 #include <linux/bug.h>
30 static inline void
31 __hrtimer_function(void *arg)
33 struct hrtimer *timer = arg;
34 enum hrtimer_restart restart = HRTIMER_RESTART;
36 if (timer->function) {
37 restart = timer->function(timer);
40 if (restart == HRTIMER_RESTART) {
42 * XXX Not implemented yet, we would need to store the
43 * expiration period, to do the callout_reset here.
45 } else {
46 timer->active = false;
50 void hrtimer_init(struct hrtimer *timer, clockid_t clock_id,
51 enum hrtimer_mode mode)
53 BUG_ON(clock_id != CLOCK_MONOTONIC);
55 memset(timer, 0, sizeof(struct hrtimer));
56 timer->clock_id = clock_id;
57 timer->ht_mode = mode;
59 lwkt_token_init(&timer->timer_token, "timer token");
60 callout_init_mp(&(timer)->timer_callout);
63 void
64 hrtimer_start_range_ns(struct hrtimer *timer, ktime_t tim,
65 u64 range_ns, const enum hrtimer_mode mode)
67 int expire_ticks = tim.tv64 / (NSEC_PER_SEC / hz);
69 if (mode == HRTIMER_MODE_ABS)
70 expire_ticks -= ticks;
72 if (expire_ticks <= 0)
73 expire_ticks = 1;
75 lwkt_gettoken(&timer->timer_token);
77 timer->active = true;
78 callout_reset(&timer->timer_callout,
79 expire_ticks, __hrtimer_function, timer);
81 lwkt_reltoken(&timer->timer_token);
84 int
85 hrtimer_cancel(struct hrtimer *timer)
87 return callout_drain(&timer->timer_callout) == 0;
90 /* Returns non-zero if the timer is already on the queue */
91 bool
92 hrtimer_active(const struct hrtimer *timer)
94 return callout_pending(&timer->timer_callout);