X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=ref_counted_gl_sync.h;h=8b6db680a2c31ffa66ce36c799f1475769937033;hb=d3e48df512d9476d3849227067792a3537bb094e;hp=5e23752dd2c3ea80e75321cc6e4453e0f5d7e884;hpb=6531415ce7a0010195cb3267c6898475d38922ac;p=nageru diff --git a/ref_counted_gl_sync.h b/ref_counted_gl_sync.h index 5e23752..8b6db68 100644 --- a/ref_counted_gl_sync.h +++ b/ref_counted_gl_sync.h @@ -6,8 +6,9 @@ // places. (We could set two fences at the same time, but they are not an // unlimited hardware resource, so it would be a bit wasteful.) -#include +#include #include +#include typedef std::shared_ptr<__GLsync> RefCountedGLsyncBase; @@ -16,7 +17,23 @@ public: RefCountedGLsync() {} RefCountedGLsync(GLenum condition, GLbitfield flags) - : RefCountedGLsyncBase(glFenceSync(condition, flags), glDeleteSync) {} + : RefCountedGLsyncBase(locked_glFenceSync(condition, flags), glDeleteSync) {} + +private: + // These are to work around apitrace bug #446. + static GLsync locked_glFenceSync(GLenum condition, GLbitfield flags) + { + std::lock_guard lock(fence_lock); + return glFenceSync(condition, flags); + } + + static void locked_glDeleteSync(GLsync sync) + { + std::lock_guard lock(fence_lock); + glDeleteSync(sync); + } + + static std::mutex fence_lock; }; #endif // !defined(_REF_COUNTED_GL_SYNC_H)