Skip to content

Instantly share code, notes, and snippets.

@itrobotics
Last active March 21, 2022 09:23
Show Gist options
  • Save itrobotics/a680c49422a8ff995125 to your computer and use it in GitHub Desktop.
Save itrobotics/a680c49422a8ff995125 to your computer and use it in GitHub Desktop.
simple example for tasklet in Linux kernel
/*******************************************************************************
* Copyright (c) 2015 Song Yang @ ittraining
*
* All rights reserved.
* This program is free to use, but the ban on selling behavior.
* Modify the program must keep all the original text description.
*
* 保留所有權利。
* 本程式可任意使用,但是禁止販售行為。
* 修改程式時必須保留所有原有文字說明。
*
* Email: onionys@ittraining.com.tw
* Blog : http://blog.ittraining.com.tw
*******************************************************************************/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
MODULE_LICENSE("Dual BSD/GPL");
static void my_tasklet_handler(unsigned long flag);
DECLARE_TASKLET(my_tasklet, my_tasklet_handler, 0);
static void my_tasklet_handler(unsigned long flag)
{
tasklet_disable(&my_tasklet);
printk("my_tasklet run: do what the tasklet want to do....\n");
tasklet_enable(&my_tasklet);
}
static int hello_tasklet_init(void)
{
printk("module init start. \n");
printk("Hello tasklet!\n");
tasklet_schedule(&my_tasklet);
printk("module init end.\n");
return 0;
}
static void hello_tasklet_exit(void)
{
tasklet_kill(&my_tasklet);
printk("Goodbye, tasklet!\n");
}
module_init(hello_tasklet_init);
module_exit(hello_tasklet_exit);
@meesokim
Copy link

This source code should be changed from DECLARE_TASKLET to DECLARE_TASKLET_OLD.

@neliy
Copy link

neliy commented Mar 21, 2022

DECLARE_TASKLET(my_tasklet, my_tasklet_handler, 0);
should be changed to
DECLARE_TASKLET_OLD(my_tasklet, my_tasklet_handler);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment