| 1 | /* |
| 2 | * Copyright (c) 2016-2022 Joris Vink <[email protected]> |
| 3 | * |
| 4 | * Permission to use, copy, modify, and distribute this software for any |
| 5 | * purpose with or without fee is hereby granted, provided that the above |
| 6 | * copyright notice and this permission notice appear in all copies. |
| 7 | * |
| 8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 15 | */ |
| 16 | |
| 17 | #include <sys/param.h> |
| 18 | #include <sys/types.h> |
| 19 | #include <sys/queue.h> |
| 20 | |
| 21 | #include "kore.h"cxx . . $ `<file>/include/kore/kore.h`/ |
| 22 | |
| 23 | TAILQ_HEADcxx . . $ `<external>/2546723208511035544/queue.h:372:9`!(timerlist, kore_timer) kore_timerscxx . . $ kore_timers.; |
| 24 | |
| 25 | void |
| 26 | kore_timer_initcxx . . $ kore_timer_init(49f6e7a06ebc5aa8).(void) |
| 27 | { |
| 28 | TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&kore_timers); |
| 29 | } |
| 30 | |
| 31 | struct kore_timercxx . . $ kore_timer# * |
| 32 | kore_timer_addcxx . . $ kore_timer_add(6973730e1cd229bb).(void (*cb)(void *, u_int64_tcxx . . $ u_int64_t#), u_int64_tcxx . . $ u_int64_t# interval, |
| 33 | void *arg, int flags) |
| 34 | { |
| 35 | struct kore_timercxx . . $ kore_timer# *timer, *t; |
| 36 | |
| 37 | timer = kore_malloccxx . . $ kore_malloc(bfcfa4d6b7f7ef64).(sizeof(*timer)); |
| 38 | |
| 39 | timer->cbcxx . . $ kore_timer#cb. = cb; |
| 40 | timer->argcxx . . $ kore_timer#arg. = arg; |
| 41 | timer->flagscxx . . $ kore_timer#flags. = flags; |
| 42 | timer->intervalcxx . . $ kore_timer#interval. = interval; |
| 43 | timer->nextruncxx . . $ kore_timer#nextrun. = kore_time_mscxx . . $ kore_time_ms(f708dce9a8856c70).() + timer->intervalcxx . . $ kore_timer#interval.; |
| 44 | |
| 45 | TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(t, &kore_timers, list) { |
| 46 | if (t->nextruncxx . . $ kore_timer#nextrun. > timer->nextruncxx . . $ kore_timer#nextrun.) { |
| 47 | TAILQ_INSERT_BEFOREcxx . . $ `<external>/2546723208511035544/queue.h:419:9`!(t, timer, list); |
| 48 | return (timer); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&kore_timers, timer, list); |
| 53 | return (timer); |
| 54 | } |
| 55 | |
| 56 | void |
| 57 | kore_timer_removecxx . . $ kore_timer_remove(6ececa34a2cdf8cd).(struct kore_timercxx . . $ kore_timer# *timer) |
| 58 | { |
| 59 | TAILQ_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:426:9`!(&kore_timers, timer, list); |
| 60 | kore_freecxx . . $ kore_free(5d22bdacc48458e8).(timer); |
| 61 | } |
| 62 | |
| 63 | u_int64_tcxx . . $ u_int64_t# |
| 64 | kore_timer_next_runcxx . . $ kore_timer_next_run(ecdaa1632f49f591).(u_int64_tcxx . . $ u_int64_t# now) |
| 65 | { |
| 66 | struct kore_timercxx . . $ kore_timer# *timer; |
| 67 | |
| 68 | if ((timer = TAILQ_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:458:9`!(&kore_timers)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 69 | if (timer->nextruncxx . . $ kore_timer#nextrun. > now) |
| 70 | return (timer->nextruncxx . . $ kore_timer#nextrun. - now); |
| 71 | return (0); |
| 72 | } |
| 73 | |
| 74 | return (KORE_WAIT_INFINITEcxx . . $ `include/kore/kore.h:97:9`!); |
| 75 | } |
| 76 | |
| 77 | void |
| 78 | kore_timer_runcxx . . $ kore_timer_run(2c44cd906ae4e829).(u_int64_tcxx . . $ u_int64_t# now) |
| 79 | { |
| 80 | struct kore_timercxx . . $ kore_timer# *timer, *t, *prev; |
| 81 | |
| 82 | prev = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 83 | |
| 84 | while ((timer = TAILQ_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:458:9`!(&kore_timers)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 85 | if (timer == prev) |
| 86 | break; |
| 87 | |
| 88 | if (timer->nextruncxx . . $ kore_timer#nextrun. > now) |
| 89 | break; |
| 90 | |
| 91 | TAILQ_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:426:9`!(&kore_timers, timer, list); |
| 92 | timer->cbcxx . . $ kore_timer#cb.(timer->argcxx . . $ kore_timer#arg., now); |
| 93 | |
| 94 | if (timer->flagscxx . . $ kore_timer#flags. & KORE_TIMER_ONESHOTcxx . . $ `include/kore/kore.h:211:9`!) { |
| 95 | kore_freecxx . . $ kore_free(5d22bdacc48458e8).(timer); |
| 96 | } else { |
| 97 | prev = timer; |
| 98 | timer->nextruncxx . . $ kore_timer#nextrun. = now + timer->intervalcxx . . $ kore_timer#interval.; |
| 99 | TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(t, &kore_timers, list) { |
| 100 | if (t->nextruncxx . . $ kore_timer#nextrun. > timer->nextruncxx . . $ kore_timer#nextrun.) { |
| 101 | TAILQ_INSERT_BEFOREcxx . . $ `<external>/2546723208511035544/queue.h:419:9`!(t, timer, list); |
| 102 | break; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | if (t == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 107 | TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&kore_timers, timer, list); |
| 108 | } |
| 109 | } |
| 110 | } |