Skip to content

Commit c367b77

Browse files
committed
drm/managed: Add DRM-managed alloc_ordered_workqueue
Add drmm_alloc_ordered_workqueue(), a helper that provides managed ordered workqueue cleanup. The workqueue will be destroyed with the final reference of the DRM device. Reviewed-by: Thomas Zimmermann <[email protected]> Reviewed-by: Maxime Ripard <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Louis Chauvet <[email protected]>
1 parent 16d22ba commit c367b77

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

drivers/gpu/drm/drm_managed.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,3 +310,11 @@ void __drmm_mutex_release(struct drm_device *dev, void *res)
310310
mutex_destroy(lock);
311311
}
312312
EXPORT_SYMBOL(__drmm_mutex_release);
313+
314+
void __drmm_workqueue_release(struct drm_device *device, void *res)
315+
{
316+
struct workqueue_struct *wq = res;
317+
318+
destroy_workqueue(wq);
319+
}
320+
EXPORT_SYMBOL(__drmm_workqueue_release);

include/drm/drm_managed.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,16 @@ void __drmm_mutex_release(struct drm_device *dev, void *res);
127127
drmm_add_action_or_reset(dev, __drmm_mutex_release, lock); \
128128
}) \
129129

130+
void __drmm_workqueue_release(struct drm_device *device, void *wq);
131+
132+
#define drmm_alloc_ordered_workqueue(dev, fmt, flags, args...) \
133+
({ \
134+
struct workqueue_struct *wq = alloc_ordered_workqueue(fmt, flags, ##args); \
135+
wq ? ({ \
136+
int ret = drmm_add_action_or_reset(dev, __drmm_workqueue_release, wq); \
137+
ret ? ERR_PTR(ret) : wq; \
138+
}) : \
139+
wq; \
140+
})
141+
130142
#endif

0 commit comments

Comments
 (0)