In preparation for adding more sync object types
that will need Await requests of their own, factor
out some setup and finalization code from
ProcSyncAwait() into SyncAwaitPrologue() and
SyncAwaitEpilogue()

Signed-off-by: James Jones <jajo...@nvidia.com>
---
 Xext/sync.c |  110 +++++++++++++++++++++++++++++++++++------------------------
 1 files changed, 65 insertions(+), 45 deletions(-)

diff --git a/Xext/sync.c b/Xext/sync.c
index 1a2d55d..d17a752 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -1465,6 +1465,66 @@ ProcSyncDestroyCounter(ClientPtr client)
     return Success;
 }
 
+static SyncAwaitUnion*
+SyncAwaitPrologue(ClientPtr client, int items)
+{
+    SyncAwaitUnion *pAwaitUnion;
+
+    /*  all the memory for the entire await list is allocated
+     *  here in one chunk
+     */
+    pAwaitUnion = malloc((items+1) * sizeof(SyncAwaitUnion));
+    if (!pAwaitUnion)
+       return NULL;
+
+    /* first item is the header, remainder are real wait conditions */
+
+    pAwaitUnion->header.delete_id = FakeClientID(client->index);
+    if (!AddResource(pAwaitUnion->header.delete_id, RTAwait, pAwaitUnion))
+    {
+       free(pAwaitUnion);
+       return NULL;
+    }
+
+    pAwaitUnion->header.client = client;
+    pAwaitUnion->header.num_waitconditions = 0;
+
+    return pAwaitUnion;
+}
+
+static void
+SyncAwaitEpilogue(ClientPtr client, int items, SyncAwaitUnion *pAwaitUnion)
+{
+    SyncAwait *pAwait;
+    int i;
+
+    IgnoreClient(client);
+
+    /* see if any of the triggers are already true */
+
+    pAwait = &(pAwaitUnion+1)->await; /* skip over header */
+    for (i = 0; i < items; i++, pAwait++)
+    {
+       CARD64 value;
+
+       /*  don't have to worry about NULL counters because the request
+        *  errors before we get here out if they occur
+        */
+       switch (pAwait->trigger.pSync->type) {
+       case SYNC_COUNTER:
+           value = ((SyncCounter *)pAwait->trigger.pSync)->value;
+           break;
+       default:
+           XSyncIntToValue(&value, 0);
+       }
+
+       if ((*pAwait->trigger.CheckTrigger)(&pAwait->trigger, value))
+       {
+           (*pAwait->trigger.TriggerFired)(&pAwait->trigger);
+           break; /* once is enough */
+       }
+    }
+}
 
 /*
  * ** Await
@@ -1496,28 +1556,12 @@ ProcSyncAwait(ClientPtr client)
        return BadValue;
     }
 
-    pProtocolWaitConds = (xSyncWaitCondition *) & stuff[1];
-
-    /*  all the memory for the entire await list is allocated
-     *  here in one chunk
-     */
-    pAwaitUnion = malloc((items+1) * sizeof(SyncAwaitUnion));
-    if (!pAwaitUnion)
+    if (!(pAwaitUnion = SyncAwaitPrologue(client, items)))
        return BadAlloc;
 
-    /* first item is the header, remainder are real wait conditions */
-
-    pAwaitUnion->header.delete_id = FakeClientID(client->index);
-    if (!AddResource(pAwaitUnion->header.delete_id, RTAwait, pAwaitUnion))
-    {
-       free(pAwaitUnion);
-       return BadAlloc;
-    }
-
     /* don't need to do any more memory allocation for this request! */
 
-    pAwaitUnion->header.client = client;
-    pAwaitUnion->header.num_waitconditions = 0;
+    pProtocolWaitConds = (xSyncWaitCondition *) & stuff[1];
 
     pAwait = &(pAwaitUnion+1)->await; /* skip over header */
     for (i = 0; i < items; i++, pProtocolWaitConds++, pAwait++)
@@ -1525,7 +1569,7 @@ ProcSyncAwait(ClientPtr client)
        if (pProtocolWaitConds->counter == None) /* XXX protocol change */
        {
            /*  this should take care of removing any triggers created by
-            *  this request that have already been registered on counters
+            *  this request that have already been registered on sync objects
             */
            FreeResource(pAwaitUnion->header.delete_id, RT_NONE);
            client->errorValue = pProtocolWaitConds->counter;
@@ -1546,7 +1590,7 @@ ProcSyncAwait(ClientPtr client)
        if (status != Success)
        {
            /*  this should take care of removing any triggers created by
-            *  this request that have already been registered on counters
+            *  this request that have already been registered on sync objects
             */
            FreeResource(pAwaitUnion->header.delete_id, RT_NONE);
            return status;
@@ -1561,32 +1605,8 @@ ProcSyncAwait(ClientPtr client)
        pAwaitUnion->header.num_waitconditions++;
     }
 
-    IgnoreClient(client);
-
-    /* see if any of the triggers are already true */
+    SyncAwaitEpilogue(client, items, pAwaitUnion);
 
-    pAwait = &(pAwaitUnion+1)->await; /* skip over header */
-    for (i = 0; i < items; i++, pAwait++)
-    {
-       CARD64 value;
-
-       /*  don't have to worry about NULL counters because the request
-        *  errors before we get here out if they occur
-        */
-       switch (pAwait->trigger.pSync->type) {
-       case SYNC_COUNTER:
-           value = ((SyncCounter *)pAwait->trigger.pSync)->value;
-           break;
-       default:
-           XSyncIntToValue(&value, 0);
-       }
-
-       if ((*pAwait->trigger.CheckTrigger)(&pAwait->trigger, value))
-       {
-           (*pAwait->trigger.TriggerFired)(&pAwait->trigger);
-           break; /* once is enough */
-       }
-    }
     return Success;
 }
 
-- 
1.7.1

_______________________________________________
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to