Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.52 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <sys/module.h>
  3. #include <sys/systm.h>
  4. #include <sys/errno.h>
  5. #include <sys/param.h>
  6. #include <sys/kernel.h>
  7. #include <sys/queue.h>
  8. #include <sys/taskqueue.h>
  9. #include <sys/malloc.h>
  10.  
  11. void static repeater_proc(void *, int);
  12. void init_repeater(void);
  13.  
  14. struct taskqueue;
  15.  
  16. struct taskq {
  17.     struct taskqueue *tq_queue;
  18. };
  19.  
  20. struct controller {
  21.     struct task fail_req_task;
  22. };
  23.  
  24. static void
  25. repeater_proc(void *arg, int npending) {
  26.     char *str = arg;
  27.     printf("Received message %s\n", str);
  28. }
  29.  
  30. void
  31. init_repeater()
  32. {
  33.     struct taskq *tq;
  34.     struct controller *ctrl;
  35.  
  36.     struct task *setroot_task;
  37.  
  38.     setroot_task = malloc(sizeof(struct task), M_TEMP, M_NOWAIT);
  39.  
  40.     tq = malloc(sizeof(struct taskq), M_TEMP, M_WAITOK);
  41.     ctrl = malloc(sizeof(struct controller), M_TEMP, M_WAITOK);
  42.  
  43.     tq->tq_queue = taskqueue_create("farhan", M_NOWAIT | M_ZERO,
  44.         taskqueue_thread_enqueue, &tq->tq_queue);
  45.  
  46.     taskqueue_start_threads(&tq->tq_queue, 1, PI_DISK, "%s Test456", "Test123");
  47.  
  48.     TASK_INIT(&ctrl->fail_req_task, 0, repeater_proc, "Test");
  49.  
  50. }
  51.  
  52. static int
  53. repeater_loader(struct module *m, int what, void *arg)
  54. {
  55.     int err = 0;
  56.  
  57.     printf("Within the loader\n");
  58.  
  59.     switch (what) {
  60.     case MOD_LOAD:
  61.         init_repeater();
  62.         uprintf("Repeater KLD loaded.\n");
  63.         break;
  64.     case MOD_UNLOAD:
  65.         uprintf("Repeater KLD unloaded.\n");
  66.         break;
  67.     }
  68.     return(err);
  69. }
  70.  
  71. static moduledata_t repeater_mod = {
  72.     "repeater",
  73.     repeater_loader,
  74.     NULL
  75. };
  76.  
  77. DECLARE_MODULE(repeater, repeater_mod, SI_SUB_KLD, SI_ORDER_ANY);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement