diff mbox series

[2/4] drm: Introduce drm_modeset_lock_all_ctx_retry()

Message ID 20210715184954.7794-3-ville.syrjala@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series drm: Make modeset locking easier | expand

Commit Message

Ville Syrjälä July 15, 2021, 6:49 p.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Layer drm_modeset_lock_all_ctx_retry() on top of
drm_modeset_lock_ctx_retry() to make the fairly common
"let's lock everything" pattern nicer.

Currently we have DRM_MODESET_LOCK_ALL_{BEGIN,END}() for this
but I don't really like it due to the magic gotos within,
which makes it hard to use if you want to do multiple steps
between the BEGING/END. One would either have to know the
name of the magic label, or always wrap the whole thing into
a function so only the single call appears between the BEGIN/END.

Cc: Sean Paul <seanpaul@chromium.org>
Cc: Daniel Vetter <daniel@ffwll.ch>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 include/drm/drm_modeset_lock.h | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/include/drm/drm_modeset_lock.h b/include/drm/drm_modeset_lock.h
index 5eaad2533de5..2e2548680aaa 100644
--- a/include/drm/drm_modeset_lock.h
+++ b/include/drm/drm_modeset_lock.h
@@ -223,4 +223,10 @@  void _drm_modeset_lock_end(struct drm_modeset_acquire_ctx *ctx,
 	     _drm_modeset_lock_loop(&(ret)); \
 	     _drm_modeset_lock_end((ctx), (state), &(ret)))
 
+#define drm_modeset_lock_all_ctx_retry(dev, ctx, state, flags, ret) \
+	for (_drm_modeset_lock_begin((ctx), (state), (flags), &(ret)); \
+	     _drm_modeset_lock_loop(&(ret)); \
+	     _drm_modeset_lock_end((ctx), (state), &(ret))) \
+		for_each_if(((ret) = drm_modeset_lock_all_ctx((dev), (ctx))) == 0)
+
 #endif /* DRM_MODESET_LOCK_H_ */