| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 1 | #ifndef	__WLAN_THREAD_H_ | 
 | 2 | #define	__WLAN_THREAD_H_ | 
 | 3 |  | 
 | 4 | #include	<linux/kthread.h> | 
 | 5 |  | 
 | 6 | struct wlan_thread { | 
 | 7 | 	struct task_struct *task; | 
 | 8 | 	wait_queue_head_t waitq; | 
 | 9 | 	pid_t pid; | 
 | 10 | 	void *priv; | 
 | 11 | }; | 
 | 12 |  | 
 | 13 | static inline void wlan_activate_thread(struct wlan_thread * thr) | 
 | 14 | { | 
 | 15 | 	/** Record the thread pid */ | 
 | 16 | 	thr->pid = current->pid; | 
 | 17 |  | 
 | 18 | 	/** Initialize the wait queue */ | 
 | 19 | 	init_waitqueue_head(&thr->waitq); | 
 | 20 | } | 
 | 21 |  | 
 | 22 | static inline void wlan_deactivate_thread(struct wlan_thread * thr) | 
 | 23 | { | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 24 | 	lbs_deb_enter(LBS_DEB_THREAD); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 25 |  | 
 | 26 | 	thr->pid = 0; | 
 | 27 |  | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 28 | 	lbs_deb_leave(LBS_DEB_THREAD); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 29 | } | 
 | 30 |  | 
 | 31 | static inline void wlan_create_thread(int (*wlanfunc) (void *), | 
 | 32 | 				      struct wlan_thread * thr, char *name) | 
 | 33 | { | 
 | 34 | 	thr->task = kthread_run(wlanfunc, thr, "%s", name); | 
 | 35 | } | 
 | 36 |  | 
 | 37 | static inline int wlan_terminate_thread(struct wlan_thread * thr) | 
 | 38 | { | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 39 | 	lbs_deb_enter(LBS_DEB_THREAD); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 40 |  | 
 | 41 | 	/* Check if the thread is active or not */ | 
 | 42 | 	if (!thr->pid) { | 
 | 43 | 		printk(KERN_ERR "Thread does not exist\n"); | 
 | 44 | 		return -1; | 
 | 45 | 	} | 
 | 46 | 	kthread_stop(thr->task); | 
 | 47 |  | 
| Holger Schurig | 9012b28 | 2007-05-25 11:27:16 -0400 | [diff] [blame] | 48 | 	lbs_deb_leave(LBS_DEB_THREAD); | 
| Marcelo Tosatti | 876c9d3 | 2007-02-10 12:25:27 -0200 | [diff] [blame] | 49 | 	return 0; | 
 | 50 | } | 
 | 51 |  | 
 | 52 | #endif |