thread.h 920 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef __WLAN_THREAD_H_
  2. #define __WLAN_THREAD_H_
  3. #include <linux/kthread.h>
  4. struct wlan_thread {
  5. struct task_struct *task;
  6. wait_queue_head_t waitq;
  7. pid_t pid;
  8. void *priv;
  9. };
  10. static inline void wlan_activate_thread(struct wlan_thread * thr)
  11. {
  12. /** Record the thread pid */
  13. thr->pid = current->pid;
  14. /** Initialize the wait queue */
  15. init_waitqueue_head(&thr->waitq);
  16. }
  17. static inline void wlan_deactivate_thread(struct wlan_thread * thr)
  18. {
  19. ENTER();
  20. thr->pid = 0;
  21. LEAVE();
  22. }
  23. static inline void wlan_create_thread(int (*wlanfunc) (void *),
  24. struct wlan_thread * thr, char *name)
  25. {
  26. thr->task = kthread_run(wlanfunc, thr, "%s", name);
  27. }
  28. static inline int wlan_terminate_thread(struct wlan_thread * thr)
  29. {
  30. ENTER();
  31. /* Check if the thread is active or not */
  32. if (!thr->pid) {
  33. printk(KERN_ERR "Thread does not exist\n");
  34. return -1;
  35. }
  36. kthread_stop(thr->task);
  37. LEAVE();
  38. return 0;
  39. }
  40. #endif