[Mesa-dev] [PATCH 03/11] pipe-loader-drm: protect create_screen() and destroy() calls with mutex

Rob Herring robh at kernel.org
Thu Jun 23 23:58:02 UTC 2016


Creating a screen needs to be an atomic operation in order to support
reusing existing screen. With this, driver private mutexes in
create screen functions can be removed.

Signed-off-by: Rob Herring <robh at kernel.org>
Cc: Emil Velikov <emil.l.velikov at gmail.com>
---
 src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
index 7bdd2ec..d1a6276 100644
--- a/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
+++ b/src/gallium/auxiliary/pipe-loader/pipe_loader_drm.c
@@ -41,6 +41,7 @@
 #include "pipe_loader_priv.h"
 #include "pipe/p_screen.h"
 
+#include "os/os_thread.h"
 #include "util/u_memory.h"
 #include "util/u_dl.h"
 #include "util/u_debug.h"
@@ -63,6 +64,8 @@ struct pipe_loader_drm_device {
 
 static const struct pipe_loader_ops pipe_loader_drm_ops;
 
+pipe_static_mutex(loader_mutex);
+
 #ifdef GALLIUM_STATIC_TARGETS
 static const struct drm_conf_ret throttle_ret = {
    DRM_CONF_INT,
@@ -272,6 +275,8 @@ pipe_loader_drm_release(struct pipe_loader_device **dev)
    struct pipe_loader_drm_device *ddev = pipe_loader_drm_device(*dev);
    struct pipe_screen *pscreen = ddev->base.pscreen;
 
+   pipe_mutex_lock(loader_mutex);
+
    pscreen->destroy(pscreen);
 
 #ifndef GALLIUM_STATIC_TARGETS
@@ -283,6 +288,7 @@ pipe_loader_drm_release(struct pipe_loader_device **dev)
    FREE(ddev->base.driver_name);
    FREE(ddev);
    *dev = NULL;
+   pipe_mutex_unlock(loader_mutex);
 }
 
 static const struct drm_conf_ret *
@@ -303,8 +309,10 @@ pipe_loader_drm_create_screen(struct pipe_loader_device *dev)
    struct pipe_loader_drm_device *ddev = pipe_loader_drm_device(dev);
    struct pipe_screen *pscreen;
 
+   pipe_mutex_lock(loader_mutex);
    pscreen = ddev->dd->create_screen(ddev->fd);
    ddev->base.pscreen = pscreen;
+   pipe_mutex_unlock(loader_mutex);
    return pscreen;
 }
 
-- 
2.9.0



More information about the mesa-dev mailing list