Tasklet#

See: embetronicx tutorial

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <linux/interrupt.h>

static struct tasklet_struct tlet;
static wait_queue_head_t wait;
static int loop = 5;
static int timeout = 0;

static void print_tasklet(unsigned long data)
{
	pr_debug("invoked from tasklet\n");

	if (!loop) {
		timeout = 1;
		wake_up_interruptible(wait);
		return;
	}

	loop--;
	tasklet_schedule(tlet);
}

static int read_tasklet(struct file *filp, char __user *buf, size_t size, loff_t *f_pos)
{
	tasklet_init(tlet, jiq_print_tasklet, (unsigned long)data);

	tasklet_schedule(tlet);
	wait_event_interruptible(jiq_wait, timeout);
	return 0;
}

static struct file_operations fops = {
	.read = read_tasklet,
};

Here u can assume that wait_queue_head_t is already initilized.

tasklet is linked to read call, when read call is triggered, tasklet gets schedule. Which schedule itself in print_tasklet and read call sleep until print_tasklet triggered loop times and then waked up by print_tasklet.

References#