[VDPAU] [PATCH 3/4] vdpau_wrapper: make initialization of library handles thread-safe

Rémi Denis-Courmont remi at remlab.net
Wed Oct 29 05:47:01 PDT 2014


From: Rémi Denis-Courmont <remid at nvidia.com>

---
 src/vdpau_wrapper.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/vdpau_wrapper.c b/src/vdpau_wrapper.c
index 0360d4d..7d4885d 100644
--- a/src/vdpau_wrapper.c
+++ b/src/vdpau_wrapper.c
@@ -525,17 +525,21 @@ VdpStatus vdp_device_create_x11(
 )
 {
     static pthread_once_t once = PTHREAD_ONCE_INIT;
-    VdpStatus status;
+    static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
+    VdpStatus status = VDP_STATUS_OK;
 
     pthread_once(&once, init_fixes);
 
+    pthread_mutex_lock(&lock);
     if (!_vdp_imp_device_create_x11_proc) {
         status = _vdp_open_driver(display, screen);
-        if (status != VDP_STATUS_OK) {
+        if (status != VDP_STATUS_OK)
             _vdp_close_driver();
-            return status;
-        }
     }
+    pthread_mutex_unlock(&lock);
+
+    if (status != VDP_STATUS_OK)
+        return status;
 
     status = _vdp_imp_device_create_x11_proc(
         display,
-- 
1.9.1



More information about the VDPAU mailing list