aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/libertas/thread.h
blob: 207b8a6cc33d632c0214a5d75eac182ff7dc5ef6 (plain) (blame)
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef	__WLAN_THREAD_H_
#define	__WLAN_THREAD_H_

#include	<linux/kthread.h>

struct wlan_thread {
	struct task_struct *task;
	wait_queue_head_t waitq;
	pid_t pid;
	void *priv;
};

static inline void wlan_activate_thread(struct wlan_thread * thr)
{
	/** Record the thread pid */
	thr->pid = current->pid;

	/** Initialize the wait queue */
	init_waitqueue_head(&thr->waitq);
}

static inline void wlan_deactivate_thread(struct wlan_thread * thr)
{
	ENTER();

	thr->pid = 0;

	LEAVE();
}

static inline void wlan_create_thread(int (*wlanfunc) (void *),
				      struct wlan_thread * thr, char *name)
{
	thr->task = kthread_run(wlanfunc, thr, "%s", name);
}

static inline int wlan_terminate_thread(struct wlan_thread * thr)
{
	ENTER();

	/* Check if the thread is active or not */
	if (!thr->pid) {
		printk(KERN_ERR "Thread does not exist\n");
		return -1;
	}
	kthread_stop(thr->task);

	LEAVE();
	return 0;
}

#endif