1 /* 2 * timer.c a shim layer around osmo timer to use libubox/uloop timers 3 * 4 * Copyright (C) 2023 Alexander Couzens <lynxis@fe80.eu> 5 * 6 * This library is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public 8 * License as published by the Free Software Foundation; either 9 * version 2 of the License, or (at your option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this library; if not, write to the 18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301 USA. 20 */ 21 22 23 #include <limits.h> 24 25 #include "timer.h" 26 27 static void osmo_timer_call_callback(struct uloop_timeout *timeout) 28 { 29 struct pipe_timer *timer = container_of(timeout, struct pipe_timer, timeout); 30 31 if (timer->cb) 32 timer->cb(timer->data); 33 } 34 35 void osmo_timer_setup(struct pipe_timer *timer, void (*cb)(void *data), void *data) 36 { 37 timer->timeout.cb = osmo_timer_call_callback; 38 timer->cb = cb; 39 timer->data = data; 40 } 41 42 void osmo_timer_add(struct pipe_timer *timer) 43 { 44 uloop_timeout_add(&timer->timeout); 45 } 46 47 void osmo_timer_schedule(struct pipe_timer *timer, int seconds, int microseconds) 48 { 49 int msecs = seconds * 1000 + microseconds / 1000; 50 if (msecs == 0 && microseconds > 0) 51 msecs = 1; 52 53 uloop_timeout_set(&timer->timeout, msecs); 54 } 55 56 void osmo_timer_del(struct pipe_timer *timer) 57 { 58 uloop_timeout_cancel(&timer->timeout); 59 } 60 61 int osmo_timer_pending(const struct pipe_timer *timer) 62 { 63 return timer->timeout.pending; 64 } 65 66 int osmo_timer_remaining(struct pipe_timer *timer, 67 const struct timeval *now, 68 struct timeval *remaining) 69 { 70 int64_t remain = uloop_timeout_remaining64(&timer->timeout); 71 if (remain > INT_MAX) 72 return INT_MAX; 73 74 return remain; 75 } 76
This page was automatically generated by LXR 0.3.1. • OpenWrt