瀏覽代碼

Merge pull request #317 from wurrrrrrrrrr/master

Improve example in 15.2 Work queues with error handling and cleanup
Jim Huang 3 天之前
父節點
當前提交
989e9941a9
共有 1 個文件被更改,包括 5 次插入0 次删除
  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);
 }