deleting timer that re-registers itself

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxxx
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]

  Powered by Linux