History

lockdep: Add an in_workqueue_context() lockdep-based test function

Some recent uses of RCU make use of workqueues. In these uses, execution within the context of a specific workqueue takes the place of the usual RCU read-side primitives such as rcu_read_lock(), and flushing of workqueues takes the place of the usual RCU grace-period primitives. Checking for correct use of rcu_dereference() in such cases requires a test of whether the code is executing in the context of a particular workqueue. This commit adds an in_workqueue_context() function that provides this test. This new function is only defined when lockdep is enabled, which allows it to be used as the second argument of rcu_dereference_check().

Paul E. McKenney committed 16 years ago

Commit a25909a1 parent 71d1d5c2 files · +19 −0Browse files

Showing the changes to kernel/workqueue.c (1 of 2 files). Show all

Unified · Split

kernel/workqueue.c+15−0
@@ -68,6 +68,21 @@ struct workqueue_struct { · 67 unmodified lines
6868 #endif
6969 };
7070
71+#ifdef CONFIG_LOCKDEP
72+/**
73+ * in_workqueue_context() - in context of specified workqueue?
74+ * @wq: the workqueue of interest
75+ *
76+ * Checks lockdep state to see if the current task is executing from
77+ * within a workqueue item. This function exists only if lockdep is
78+ * enabled.
79+ */
80+int in_workqueue_context(struct workqueue_struct *wq)
81+{
82+ return lock_is_held(&wq->lockdep_map);
83+}
84+#endif
85+
7186 #ifdef CONFIG_DEBUG_OBJECTS_WORK
7287
7388 static struct debug_obj_descr work_debug_descr;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t