[PATCH libXext (rev3) 3/5] Initial Fence Sync Object support

James Jones jajones at nvidia.com
Thu Dec 2 09:26:29 PST 2010


Allows creating and managing binary state sync
objects.  Currently they aren't useful because
there is not yet a way to wait for them or
query their state.  X fence objects are owned
by a screen.  As Aaron Plattner pointed out,
screens are identified by a drawable in X
protocol, so XSyncCreateFence() takes a drawable
to identify which screen to create the fence on.

Signed-off-by: James Jones <jajones at nvidia.com>
Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
---
 include/X11/extensions/sync.h |   21 ++++++++++
 src/XSync.c                   |   85 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 106 insertions(+), 0 deletions(-)

diff --git a/include/X11/extensions/sync.h b/include/X11/extensions/sync.h
index af49c37..7f4b5c5 100644
--- a/include/X11/extensions/sync.h
+++ b/include/X11/extensions/sync.h
@@ -335,6 +335,27 @@ extern Status XSyncGetPriority(
     int* /*return_priority*/
 );
 
+extern XSyncFence XSyncCreateFence(
+    Display* /*dpy*/,
+    Drawable /*d*/,
+    Bool /*initially_triggered*/
+);
+
+extern Bool XSyncTriggerFence(
+    Display* /*dpy*/,
+    XSyncFence /*fence*/
+);
+
+extern Bool XSyncResetFence(
+    Display* /*dpy*/,
+    XSyncFence /*fence*/
+);
+
+extern Bool XSyncDestroyFence(
+    Display* /*dpy*/,
+    XSyncFence /*fence*/
+);
+
 _XFUNCPROTOEND
 
 #endif /* _SYNC_SERVER */
diff --git a/src/XSync.c b/src/XSync.c
index 99b8b2b..5236b40 100644
--- a/src/XSync.c
+++ b/src/XSync.c
@@ -92,6 +92,7 @@ static XExtensionHooks sync_extension_hooks = {
 static char    *sync_error_list[] = {
     "BadCounter",
     "BadAlarm",
+    "BadFence",
 };
 
 typedef struct _SyncVersionInfoRec {
@@ -102,6 +103,7 @@ typedef struct _SyncVersionInfoRec {
 
 static /* const */ SyncVersionInfo supported_versions[] = {
     { 3 /* major */, 0 /* minor */, 2 /* num_errors */ },
+    { 3 /* major */, 1 /* minor */, 3 /* num_errors */ },
 };
 
 #define NUM_VERSIONS (sizeof(supported_versions)/sizeof(supported_versions[0]))
@@ -760,6 +762,89 @@ XSyncGetPriority(Display *dpy, XID client_resource_id, int *return_priority)
     return True;
 }
 
+XSyncFence
+XSyncCreateFence(Display *dpy, Drawable d, Bool initially_triggered)
+{
+    XExtDisplayInfo *info = find_display(dpy);
+    xSyncCreateFenceReq *req;
+    XSyncFence id;
+
+    SyncCheckExtension(dpy, info, None);
+
+    LockDisplay(dpy);
+    GetReq(SyncCreateFence, req);
+    req->reqType = info->codes->major_opcode;
+    req->syncReqType = X_SyncCreateFence;
+
+    req->d = d;
+    id = req->fid = XAllocID(dpy);
+    req->initially_triggered = initially_triggered;
+
+    UnlockDisplay(dpy);
+    SyncHandle();
+    return id;
+}
+
+Bool
+XSyncTriggerFence(Display *dpy, XSyncFence fence)
+{
+    XExtDisplayInfo *info = find_display(dpy);
+    xSyncTriggerFenceReq *req;
+
+    SyncCheckExtension(dpy, info, None);
+
+    LockDisplay(dpy);
+    GetReq(SyncTriggerFence, req);
+    req->reqType = info->codes->major_opcode;
+    req->syncReqType = X_SyncTriggerFence;
+
+    req->fid = fence;
+
+    UnlockDisplay(dpy);
+    SyncHandle();
+    return True;
+}
+
+Bool
+XSyncResetFence(Display *dpy, XSyncFence fence)
+{
+    XExtDisplayInfo *info = find_display(dpy);
+    xSyncResetFenceReq *req;
+
+    SyncCheckExtension(dpy, info, None);
+
+    LockDisplay(dpy);
+    GetReq(SyncResetFence, req);
+    req->reqType = info->codes->major_opcode;
+    req->syncReqType = X_SyncResetFence;
+
+    req->fid = fence;
+
+    UnlockDisplay(dpy);
+    SyncHandle();
+    return True;
+}
+
+Bool
+XSyncDestroyFence(Display *dpy, XSyncFence fence)
+{
+    XExtDisplayInfo *info = find_display(dpy);
+    xSyncDestroyFenceReq *req;
+
+    SyncCheckExtension(dpy, info, None);
+
+    LockDisplay(dpy);
+    GetReq(SyncDestroyFence, req);
+    req->reqType = info->codes->major_opcode;
+    req->syncReqType = X_SyncDestroyFence;
+
+    req->fid = fence;
+
+    UnlockDisplay(dpy);
+    SyncHandle();
+    return True;
+}
+
 /*
  *  Functions corresponding to the macros for manipulating 64-bit values
  */
-- 
1.7.1



More information about the xorg-devel mailing list