diff options
author | Alex Goins <agoins@nvidia.com> | 2019-04-10 13:48:02 -0500 |
---|---|---|
committer | Aaron Plattner <aplattner@nvidia.com> | 2019-04-17 14:01:17 -0700 |
commit | 7f962c70b6d9c346477f23f6c15211e749110078 (patch) | |
tree | bbba9643be3d3c3a4fbfc8c6133c22dca2635023 /miext | |
parent | 8702c938b33b9ec180d64754eb922515c7c4a98b (diff) |
xsync: Add resource inside of SyncCreate, export SyncCreate
As shown by DRI3 adding the SyncCreateFenceFromFD() function, extensions may
want to create a fence, then initialize it in their own way. This currently
can't be done without adding a function directly to Xext/sync.c due to the fact
that the RTFence resource type is private and there is no external interface to
add to it.
To facilitate other X extensions creating fences and initializing them, this
change exports SyncCreate() and adds the resource directly within it. Callers no
longer need to call AddResource() after SyncCreate(), they only need to
initialize the SyncObject.
To prevent FreeFence() and FreeCounter() from segfaulting if the call to
AddResource() fails before the sync object is initialized, this adds a new
'initialized' parameter to SyncObject that, when FALSE, causes FreeFence() and
FreeCounter() to skip de-initialization and simply free the object.
Initialization after adding the resource shouldn't otherwise be a problem due to
the single-threaded nature of X.
Signed-off-by: Alex Goins <agoins@nvidia.com>
Reviewed-by: James Jones <jajones@nvidia.com>
Signed-off-by: Aaron Plattner <aplattner@nvidia.com>
Diffstat (limited to 'miext')
-rw-r--r-- | miext/sync/misync.c | 27 | ||||
-rw-r--r-- | miext/sync/misync.h | 1 | ||||
-rw-r--r-- | miext/sync/misyncstr.h | 5 |
3 files changed, 20 insertions, 13 deletions
diff --git a/miext/sync/misync.c b/miext/sync/misync.c index 490fa0b17..0931803f6 100644 --- a/miext/sync/misync.c +++ b/miext/sync/misync.c @@ -101,24 +101,29 @@ miSyncInitFence(ScreenPtr pScreen, SyncFence * pFence, Bool initially_triggered) pFence->funcs = miSyncFenceFuncs; pScreenPriv->funcs.CreateFence(pScreen, pFence, initially_triggered); + + pFence->sync.initialized = TRUE; } void miSyncDestroyFence(SyncFence * pFence) { - ScreenPtr pScreen = pFence->pScreen; - SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen); - SyncTriggerList *ptl, *pNext; - pFence->sync.beingDestroyed = TRUE; - /* tell all the fence's triggers that the counter has been destroyed */ - for (ptl = pFence->sync.pTriglist; ptl; ptl = pNext) { - (*ptl->pTrigger->CounterDestroyed) (ptl->pTrigger); - pNext = ptl->next; - free(ptl); /* destroy the trigger list as we go */ - } - pScreenPriv->funcs.DestroyFence(pScreen, pFence); + if (pFence->sync.initialized) { + ScreenPtr pScreen = pFence->pScreen; + SyncScreenPrivPtr pScreenPriv = SYNC_SCREEN_PRIV(pScreen); + SyncTriggerList *ptl, *pNext; + + /* tell all the fence's triggers that the counter has been destroyed */ + for (ptl = pFence->sync.pTriglist; ptl; ptl = pNext) { + (*ptl->pTrigger->CounterDestroyed) (ptl->pTrigger); + pNext = ptl->next; + free(ptl); /* destroy the trigger list as we go */ + } + + pScreenPriv->funcs.DestroyFence(pScreen, pFence); + } dixFreeObjectWithPrivates(pFence, PRIVATE_SYNC_FENCE); } diff --git a/miext/sync/misync.h b/miext/sync/misync.h index dc78c5fdb..f7082d5ea 100644 --- a/miext/sync/misync.h +++ b/miext/sync/misync.h @@ -28,6 +28,7 @@ #ifndef _MISYNC_H_ #define _MISYNC_H_ +typedef struct _SyncObject SyncObject; typedef struct _SyncFence SyncFence; typedef struct _SyncTrigger SyncTrigger; diff --git a/miext/sync/misyncstr.h b/miext/sync/misyncstr.h index 2eab2aa57..2a6e84a96 100644 --- a/miext/sync/misyncstr.h +++ b/miext/sync/misyncstr.h @@ -38,13 +38,14 @@ #define SYNC_COUNTER 0 #define SYNC_FENCE 1 -typedef struct _SyncObject { +struct _SyncObject { ClientPtr client; /* Owning client. 0 for system counters */ struct _SyncTriggerList *pTriglist; /* list of triggers */ XID id; /* resource ID */ unsigned char type; /* SYNC_* */ + Bool initialized; /* FALSE if created but not initialized */ Bool beingDestroyed; /* in process of going away */ -} SyncObject; +}; typedef struct _SyncCounter { SyncObject sync; /* Common sync object data */ |