All of lore.kernel.org
 help / color / mirror / Atom feed
* deleting timer that re-registers itself
@ 2021-05-04 14:59 Hyeonggon Yoo
  2021-05-04 16:17 ` Valdis Klētnieks
  0 siblings, 1 reply; 9+ messages in thread
From: Hyeonggon Yoo @ 2021-05-04 14:59 UTC (permalink / raw)
  To: kernelnewbies

Does del_timer work well for timers that re-registers itself?
what if the timer is currently running, and del_timer is called,
and the running timer re-registers itself?

how should I handle it?

Below is my simple kernel timer example.


timer.c

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/time.h>

#define MODULE_NAME "TIMER"
#define DELAY (1 * HZ)
struct timer_data {
        int value;
        struct timer_list timer;
};

struct timer_data data = {
        .value = 0
};

void timer_callback(struct timer_list *timer) {
        struct timer_data *data = from_timer(data, timer, timer);

        data->value++;
        printk(KERN_INFO "[%s] value is = %d\n", __func__, data->value);
        mod_timer(timer, jiffies + DELAY);
}

int __init timer_init(void) {
        printk("[%s] creating timer...\n", __func__);
        timer_setup(&data.timer, timer_callback, 0);
        mod_timer(&data.timer, jiffies + DELAY);
        return 0;
}

void __exit timer_exit(void) {
        int ret = del_timer(&data.timer);
        printk("[%s] deleting timer..., ret = %d\n", __func__, ret);
}

module_init(timer_init);
module_exit(timer_exit);

MODULE_LICENSE("GPL");

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-05-05  7:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-04 14:59 deleting timer that re-registers itself Hyeonggon Yoo
2021-05-04 16:17 ` Valdis Klētnieks
2021-05-04 16:28   ` Greg KH
2021-05-04 16:35   ` Valdis Klētnieks
2021-05-04 17:01     ` Greg KH
2021-05-05  7:22       ` Hyeonggon Yoo
2021-05-04 16:36   ` Hyeonggon Yoo
2021-05-04 16:41     ` Hyeonggon Yoo
2021-05-04 16:47       ` Hyeonggon Yoo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.