[PATCH xserver (rev2) 3/9] Create SyncObject base type.
James Jones
jajones at nvidia.com
Mon Nov 8 17:44:51 PST 2010
SyncObject is now the base type for SyncCounter
and SyncFence. Data to be used by both types is
stored in the base object. Both SyncCounter and
SyncFence can be safely cast to SyncObject, and
a SyncObject can be cast to the correct type
based on SyncObject::type.
Signed-off-by: James Jones <jajones at nvidia.com>
Reviewed-by: Aaron Plattner <aplattner at nvidia.com>
Reviewed-by: Robert Morell <rmorell at nvidia.com>
---
Xext/sync.c | 111 ++++++++++++++++++++++++++++++++++----------------------
Xext/syncsrv.h | 30 ++++++++++------
2 files changed, 87 insertions(+), 54 deletions(-)
diff --git a/Xext/sync.c b/Xext/sync.c
index 16daa63..0c6de8d 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -90,7 +90,7 @@ static int SyncNumSystemCounters = 0;
static SyncCounter **SysCounterList = NULL;
#define IsSystemCounter(pCounter) \
- (pCounter && (pCounter->client == NULL))
+ (pCounter && (pCounter->sync.client == NULL))
/* these are all the alarm attributes that pertain to the alarm's trigger */
#define XSyncCAAllTrigger \
@@ -119,7 +119,7 @@ SyncDeleteTriggerFromCounter(SyncTrigger *pTrigger)
return;
pPrev = NULL;
- pCur = pTrigger->pCounter->pTriglist;
+ pCur = pTrigger->pCounter->sync.pTriglist;
while (pCur)
{
@@ -128,7 +128,7 @@ SyncDeleteTriggerFromCounter(SyncTrigger *pTrigger)
if (pPrev)
pPrev->next = pCur->next;
else
- pTrigger->pCounter->pTriglist = pCur->next;
+ pTrigger->pCounter->sync.pTriglist = pCur->next;
free(pCur);
break;
@@ -152,7 +152,7 @@ SyncAddTriggerToCounter(SyncTrigger *pTrigger)
return Success;
/* don't do anything if it's already there */
- for (pCur = pTrigger->pCounter->pTriglist; pCur; pCur = pCur->next)
+ for (pCur = pTrigger->pCounter->sync.pTriglist; pCur; pCur = pCur->next)
{
if (pCur->pTrigger == pTrigger)
return Success;
@@ -162,8 +162,8 @@ SyncAddTriggerToCounter(SyncTrigger *pTrigger)
return BadAlloc;
pCur->pTrigger = pTrigger;
- pCur->next = pTrigger->pCounter->pTriglist;
- pTrigger->pCounter->pTriglist = pCur;
+ pCur->next = pTrigger->pCounter->sync.pTriglist;
+ pTrigger->pCounter->sync.pTriglist = pCur;
if (IsSystemCounter(pTrigger->pCounter))
SyncComputeBracketValues(pTrigger->pCounter);
@@ -391,14 +391,14 @@ SyncSendCounterNotifyEvents(ClientPtr client, SyncAwait **ppAwait,
SyncTrigger *pTrigger = &(*ppAwait)->trigger;
pev->type = SyncEventBase + XSyncCounterNotify;
pev->kind = XSyncCounterNotify;
- pev->counter = pTrigger->pCounter->id;
+ pev->counter = pTrigger->pCounter->sync.id;
pev->wait_value_lo = XSyncValueLow32(pTrigger->test_value);
pev->wait_value_hi = XSyncValueHigh32(pTrigger->test_value);
pev->counter_value_lo = XSyncValueLow32(pTrigger->pCounter->value);
pev->counter_value_hi = XSyncValueHigh32(pTrigger->pCounter->value);
pev->time = currentTime.milliseconds;
pev->count = num_events - i - 1; /* events remaining */
- pev->destroyed = pTrigger->pCounter->beingDestroyed;
+ pev->destroyed = pTrigger->pCounter->sync.beingDestroyed;
}
/* swapping will be taken care of by this */
WriteEventsToClient(client, num_events, (xEvent *)pEvents);
@@ -533,7 +533,7 @@ SyncAwaitTriggerFired(SyncTrigger *pTrigger)
* always generated if the counter for one of the triggers is
* destroyed."
*/
- if (pAwait->trigger.pCounter->beingDestroyed)
+ if (pAwait->trigger.pCounter->sync.beingDestroyed)
{
ppAwait[num_events++] = pAwait;
continue;
@@ -601,7 +601,7 @@ SyncChangeCounter(SyncCounter *pCounter, CARD64 newval)
pCounter->value = newval;
/* run through triggers to see if any become true */
- for (ptl = pCounter->pTriglist; ptl; ptl = pnext)
+ for (ptl = pCounter->sync.pTriglist; ptl; ptl = pnext)
{
pnext = ptl->next;
if ((*ptl->pTrigger->CheckTrigger)(ptl->pTrigger, oldval))
@@ -693,7 +693,8 @@ SyncChangeAlarmAttributes(ClientPtr client, SyncAlarm *pAlarm, Mask mask,
XSyncCounter counter;
Mask origmask = mask;
- counter = pAlarm->trigger.pCounter ? pAlarm->trigger.pCounter->id : None;
+ counter =
+ pAlarm->trigger.pCounter ? pAlarm->trigger.pCounter->sync.id : None;
while (mask)
{
@@ -782,26 +783,56 @@ SyncChangeAlarmAttributes(ClientPtr client, SyncAlarm *pAlarm, Mask mask,
return Success;
}
-
-static SyncCounter *
-SyncCreateCounter(ClientPtr client, XSyncCounter id, CARD64 initialvalue)
+static SyncObject *
+SyncCreate(ClientPtr client, XID id, unsigned char type)
{
- SyncCounter *pCounter;
+ SyncObject *pSync;
+ RESTYPE resType;
+ unsigned long syncSize;
- if (!(pCounter = malloc(sizeof(SyncCounter))))
+ switch (type) {
+ case SYNC_COUNTER:
+ resType = RTCounter;
+ syncSize = sizeof(SyncCounter);
+ break;
+ case SYNC_FENCE:
+ resType = RTFence;
+ syncSize = sizeof(SyncFence);
+ break;
+ default:
return NULL;
+ }
- if (!AddResource(id, RTCounter, (pointer) pCounter))
+ if (!(pSync = (SyncObject *)malloc(syncSize)))
+ return NULL;
+
+ if (!AddResource(id, resType, (pointer) pSync))
{
- free(pCounter);
+ free(pSync);
return NULL;
}
- pCounter->client = client;
- pCounter->id = id;
+ pSync->client = client;
+ pSync->id = id;
+ pSync->pTriglist = NULL;
+ pSync->beingDestroyed = FALSE;
+ pSync->type = type;
+
+ return pSync;
+}
+
+
+static SyncCounter *
+SyncCreateCounter(ClientPtr client, XSyncCounter id, CARD64 initialvalue)
+{
+ SyncCounter *pCounter;
+
+ if (!(pCounter = (SyncCounter *)SyncCreate(client,
+ id,
+ SYNC_COUNTER)))
+ return NULL;
+
pCounter->value = initialvalue;
- pCounter->pTriglist = NULL;
- pCounter->beingDestroyed = FALSE;
pCounter->pSysCounterInfo = NULL;
return pCounter;
}
@@ -853,7 +884,7 @@ SyncCreateSystemCounter(
psci = malloc(sizeof(SysCounterInfo));
if (!psci)
{
- FreeResource(pCounter->id, RT_NONE);
+ FreeResource(pCounter->sync.id, RT_NONE);
return pCounter;
}
pCounter->pSysCounterInfo = psci;
@@ -873,7 +904,7 @@ void
SyncDestroySystemCounter(pointer pSysCounter)
{
SyncCounter *pCounter = (SyncCounter *)pSysCounter;
- FreeResource(pCounter->id, RT_NONE);
+ FreeResource(pCounter->sync.id, RT_NONE);
}
static void
@@ -897,7 +928,7 @@ SyncComputeBracketValues(SyncCounter *pCounter)
XSyncMaxValue(&psci->bracket_greater);
XSyncMinValue(&psci->bracket_less);
- for (pCur = pCounter->pTriglist; pCur; pCur = pCur->next)
+ for (pCur = pCounter->sync.pTriglist; pCur; pCur = pCur->next)
{
pTrigger = pCur->pTrigger;
@@ -987,9 +1018,9 @@ FreeCounter(void *env, XID id)
SyncCounter *pCounter = (SyncCounter *) env;
SyncTriggerList *ptl, *pnext;
- pCounter->beingDestroyed = TRUE;
+ pCounter->sync.beingDestroyed = TRUE;
/* tell all the counter's triggers that the counter has been destroyed */
- for (ptl = pCounter->pTriglist; ptl; ptl = pnext)
+ for (ptl = pCounter->sync.pTriglist; ptl; ptl = pnext)
{
(*ptl->pTrigger->CounterDestroyed)(ptl->pTrigger);
pnext = ptl->next;
@@ -1049,7 +1080,7 @@ FreeAwait(void *addr, XID id)
* the trigger list itself, so don't do it here.
*/
SyncCounter *pCounter = pAwait->trigger.pCounter;
- if (pCounter && !pCounter->beingDestroyed)
+ if (pCounter && !pCounter->sync.beingDestroyed)
SyncDeleteTriggerFromCounter(&pAwait->trigger);
}
free(pAwaitUnion);
@@ -1159,7 +1190,7 @@ ProcSyncListSystemCounters(ClientPtr client)
char *pname_in_reply;
SysCounterInfo *psci = SysCounterList[i]->pSysCounterInfo;
- walklist->counter = SysCounterList[i]->id;
+ walklist->counter = SysCounterList[i]->sync.id;
walklist->resolution_hi = XSyncValueHigh32(psci->resolution);
walklist->resolution_lo = XSyncValueLow32(psci->resolution);
namelen = strlen(psci->name);
@@ -1372,7 +1403,7 @@ ProcSyncDestroyCounter(ClientPtr client)
client->errorValue = stuff->counter;
return BadAccess;
}
- FreeResource(pCounter->id, RT_NONE);
+ FreeResource(pCounter->sync.id, RT_NONE);
return Success;
}
@@ -1678,7 +1709,7 @@ ProcSyncQueryAlarm(ClientPtr client)
rep.sequenceNumber = client->sequence;
pTrigger = &pAlarm->trigger;
- rep.counter = (pTrigger->pCounter) ? pTrigger->pCounter->id : None;
+ rep.counter = (pTrigger->pCounter) ? pTrigger->pCounter->sync.id : None;
#if 0 /* XXX unclear what to do, depends on whether relative value-types
* are "consumed" immediately and are considered absolute from then
@@ -1750,18 +1781,12 @@ ProcSyncCreateFence(ClientPtr client)
LEGAL_NEW_RESOURCE(stuff->fid, client);
- if (!(pFence = malloc(sizeof(SyncFence))))
+ if (!(pFence = (SyncFence *)SyncCreate(client,
+ stuff->fid,
+ SYNC_FENCE)))
return BadAlloc;
- if (!AddResource(stuff->fid, RTFence, (pointer) pFence))
- {
- free(pFence);
- return BadAlloc;
- }
-
pFence->pScreen = pDraw->pScreen;
- pFence->client = client;
- pFence->id = stuff->fid;
pFence->triggered = stuff->initially_triggered;
return client->noClientException;
@@ -2464,7 +2489,7 @@ static void
IdleTimeBlockHandler(pointer env, struct timeval **wt, pointer LastSelectMask)
{
XSyncValue idle, old_idle;
- SyncTriggerList *list = IdleTimeCounter->pTriglist;
+ SyncTriggerList *list = IdleTimeCounter->sync.pTriglist;
SyncTrigger *trig;
if (!pIdleTimeValueLess && !pIdleTimeValueGreater)
@@ -2485,7 +2510,7 @@ IdleTimeBlockHandler(pointer env, struct timeval **wt, pointer LastSelectMask)
* immediately so we can reschedule.
*/
- for (list = IdleTimeCounter->pTriglist; list; list = list->next) {
+ for (list = IdleTimeCounter->sync.pTriglist; list; list = list->next) {
trig = list->pTrigger;
if (trig->CheckTrigger(trig, old_idle)) {
AdjustWaitForDelay(wt, 0);
@@ -2511,7 +2536,7 @@ IdleTimeBlockHandler(pointer env, struct timeval **wt, pointer LastSelectMask)
idle, &overflow);
timeout = min(timeout, XSyncValueLow32 (value));
} else {
- for (list = IdleTimeCounter->pTriglist; list; list = list->next) {
+ for (list = IdleTimeCounter->sync.pTriglist; list; list = list->next) {
trig = list->pTrigger;
if (trig->CheckTrigger(trig, old_idle)) {
timeout = min(timeout, 0);
diff --git a/Xext/syncsrv.h b/Xext/syncsrv.h
index a805f28..19d5531 100644
--- a/Xext/syncsrv.h
+++ b/Xext/syncsrv.h
@@ -53,15 +53,30 @@ PERFORMANCE OF THIS SOFTWARE.
#define CARD64 XSyncValue /* XXX temporary! need real 64 bit values for Alpha */
-typedef struct _SyncCounter {
+/* Sync object types */
+#define SYNC_COUNTER 0
+#define SYNC_FENCE 1
+
+typedef struct _SyncObject {
ClientPtr client; /* Owning client. 0 for system counters */
- XSyncCounter id; /* resource ID */
- CARD64 value; /* counter value */
struct _SyncTriggerList *pTriglist; /* list of triggers */
- Bool beingDestroyed; /* in process of going away */
+ XID id; /* resource ID */
+ unsigned char type; /* SYNC_* */
+ Bool beingDestroyed; /* in process of going away */
+} SyncObject;
+
+typedef struct _SyncCounter {
+ SyncObject sync; /* Common sync object data */
+ CARD64 value; /* counter value */
struct _SysCounterInfo *pSysCounterInfo; /* NULL if not a system counter */
} SyncCounter;
+typedef struct _SyncFence {
+ SyncObject sync; /* Common sync object data */
+ ScreenPtr pScreen; /* Screen of this fence object */
+ Bool triggered; /* fence state */
+} SyncFence;
+
/*
* The System Counter interface
*/
@@ -148,13 +163,6 @@ typedef union {
SyncAwait await;
} SyncAwaitUnion;
-typedef struct _SyncFence {
- ClientPtr client; /* Owning client. */
- XSyncFence id; /* resource ID */
- ScreenPtr pScreen; /* Screen of this fence object */
- Bool triggered; /* fence state */
-} SyncFence;
-
extern pointer SyncCreateSystemCounter(
char * /* name */,
CARD64 /* inital_value */,
--
1.7.1
More information about the xorg-devel
mailing list