#include "intel_reg.h"
struct intel_fence {
+ struct intel_context *intel;
/** The fence waits for completion of this batch. */
drm_intel_bo *batch_bo;
+ mtx_t mutex;
bool signalled;
};
}
static bool
-intel_fence_has_completed(struct intel_fence *fence)
+intel_fence_has_completed_locked(struct intel_fence *fence)
{
if (fence->signalled)
return true;
return false;
}
-/**
- * Return true if the function successfully signals or has already signalled.
- * (This matches the behavior expected from __DRI2fence::client_wait_sync).
- */
static bool
-intel_fence_client_wait(struct intel_context *intel, struct intel_fence *fence,
- uint64_t timeout)
+intel_fence_has_completed(struct intel_fence *fence)
+{
+ bool ret;
+
+ mtx_lock(&fence->mutex);
+ ret = intel_fence_has_completed_locked(fence);
+ mtx_unlock(&fence->mutex);
+
+ return ret;
+}
+
+static bool
+intel_fence_client_wait_locked(struct intel_context *intel, struct intel_fence *fence,
+ uint64_t timeout)
{
if (fence->signalled)
return true;
return true;
}
+/**
+ * Return true if the function successfully signals or has already signalled.
+ * (This matches the behavior expected from __DRI2fence::client_wait_sync).
+ */
+static bool
+intel_fence_client_wait(struct intel_context *intel, struct intel_fence *fence,
+ uint64_t timeout)
+{
+ bool ret;
+
+ mtx_lock(&fence->mutex);
+ ret = intel_fence_client_wait_locked(intel, fence, timeout);
+ mtx_unlock(&fence->mutex);
+
+ return ret;
+}
+
static void
intel_fence_server_wait(struct intel_context *intel, struct intel_fence *fence)
{
if (!fence)
return NULL;
+ mtx_init(&fence->mutex, mtx_plain);
+ fence->intel = intel;
intel_fence_insert(intel, fence);
return fence;
intel_dri_client_wait_sync(__DRIcontext *ctx, void *driver_fence, unsigned flags,
uint64_t timeout)
{
- struct intel_context *intel = ctx->driverPrivate;
struct intel_fence *fence = driver_fence;
- return intel_fence_client_wait(intel, fence, timeout);
+ return intel_fence_client_wait(fence->intel, fence, timeout);
}
static void
intel_dri_server_wait_sync(__DRIcontext *ctx, void *driver_fence, unsigned flags)
{
- struct intel_context *intel = ctx->driverPrivate;
struct intel_fence *fence = driver_fence;
- intel_fence_server_wait(intel, fence);
+ /* We might be called here with a NULL fence as a result of WaitSyncKHR
+ * on a EGL_KHR_reusable_sync fence. Nothing to do here in such case.
+ */
+ if (!fence)
+ return;
+
+ intel_fence_server_wait(fence->intel, fence);
}
const __DRI2fenceExtension intelFenceExtension = {