Browse Source

Merge pull request #317 from wurrrrrrrrrr/master

Improve example in 15.2 Work queues with error handling and cleanup
Jim Huang 3 ngày trước cách đây
mục cha
commit
989e9941a9
1 tập tin đã thay đổi với 5 bổ sung0 xóa
  1. 5 0
      examples/sched.c

+ 5 - 0
examples/sched.c

@@ -16,6 +16,10 @@ static void work_handler(struct work_struct *data)
 static int __init sched_init(void)
 {
     queue = alloc_workqueue("HELLOWORLD", WQ_UNBOUND, 1);
+    if (!queue) {
+        pr_err("Failed to allocate workqueue\n");
+        return -ENOMEM;
+    }
     INIT_WORK(&work, work_handler);
     queue_work(queue, &work);
     return 0;
@@ -23,6 +27,7 @@ static int __init sched_init(void)
 
 static void __exit sched_exit(void)
 {
+    flush_workqueue(queue);
     destroy_workqueue(queue);
 }