aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/Xext/sync.c
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2009-09-06 18:48:27 +0000
committermarha <marha@users.sourceforge.net>2009-09-06 18:48:27 +0000
commita915739887477b28d924ecc8417ee107d125bd6c (patch)
treec02f315476b61892d1fd89182e18943dce8d6277 /xorg-server/Xext/sync.c
parent6f25a23db1df27e992c34f6fd4c82e83c44fc2e2 (diff)
downloadvcxsrv-a915739887477b28d924ecc8417ee107d125bd6c.tar.gz
vcxsrv-a915739887477b28d924ecc8417ee107d125bd6c.tar.bz2
vcxsrv-a915739887477b28d924ecc8417ee107d125bd6c.zip
Switched to xorg-server-1.6.99.900.tar.gz
Diffstat (limited to 'xorg-server/Xext/sync.c')
-rw-r--r--xorg-server/Xext/sync.c713
1 files changed, 221 insertions, 492 deletions
diff --git a/xorg-server/Xext/sync.c b/xorg-server/Xext/sync.c
index a006ae95b..667f8ab78 100644
--- a/xorg-server/Xext/sync.c
+++ b/xorg-server/Xext/sync.c
@@ -34,7 +34,7 @@ Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
-supporting documentation, and that the names of Digital or Olivetti
+supporting documentation, and that the names of Digital or Olivetti
not be used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission. Digital and Olivetti
make no representations about the suitability of this software
@@ -50,8 +50,6 @@ PERFORMANCE OF THIS SOFTWARE.
*/
-#define NEED_REPLIES
-#define NEED_EVENTS
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
@@ -67,9 +65,8 @@ PERFORMANCE OF THIS SOFTWARE.
#include "dixstruct.h"
#include "resource.h"
#include "opaque.h"
-#define _SYNC_SERVER
-#include <X11/extensions/sync.h>
-#include <X11/extensions/syncstr.h>
+#include <X11/extensions/syncproto.h>
+#include "syncsrv.h"
#include <stdio.h>
#if !defined(WIN32)
@@ -97,173 +94,11 @@ static SyncCounter **SysCounterList = NULL;
#define XSyncCAAllTrigger \
(XSyncCACounter | XSyncCAValueType | XSyncCAValue | XSyncCATestType)
-static int
-FreeAlarm(
- pointer /* addr */,
- XID /* id */
-);
-
-static int
-FreeAlarmClient(
- pointer /* value */,
- XID /* id */
-);
-
-static int
-FreeAwait(
- pointer /* addr */,
- XID /* id */
-);
-
-static void
-ServertimeBracketValues(
- pointer /* pCounter */,
- CARD64 * /* pbracket_less */,
- CARD64 * /* pbracket_greater */
-);
-
-static void
-ServertimeQueryValue(
- pointer /* pCounter */,
- CARD64 * /* pValue_return */
-);
-
-static void
-ServertimeWakeupHandler(
- pointer /* env */,
- int /* rc */,
- pointer /* LastSelectMask */
-);
-
-static int
-SyncInitTrigger(
- ClientPtr /* client */,
- SyncTrigger * /* pTrigger */,
- XSyncCounter /* counter */,
- Mask /* changes */
-);
-
-static void
-SAlarmNotifyEvent(
- xSyncAlarmNotifyEvent * /* from */,
- xSyncAlarmNotifyEvent * /* to */
-);
-
-static void
-SCounterNotifyEvent(
- xSyncCounterNotifyEvent * /* from */,
- xSyncCounterNotifyEvent * /* to */
-);
-
-static void
-ServertimeBlockHandler(
- pointer /* env */,
- struct timeval ** /* wt */,
- pointer /* LastSelectMask */
-);
-
-static int
-SyncAddTriggerToCounter(
- SyncTrigger * /* pTrigger */
-);
-
-extern void
-SyncAlarmCounterDestroyed(
- SyncTrigger * /* pTrigger */
-);
-
-static void
-SyncAlarmTriggerFired(
- SyncTrigger * /* pTrigger */
-);
-
-static void
-SyncAwaitTriggerFired(
- SyncTrigger * /* pTrigger */
-);
-
-static int
-SyncChangeAlarmAttributes(
- ClientPtr /* client */,
- SyncAlarm * /* pAlarm */,
- Mask /* mask */,
- CARD32 * /* values */
-);
-
-static Bool
-SyncCheckTriggerNegativeComparison(
- SyncTrigger * /* pTrigger */,
- CARD64 /* oldval */
-);
-
-static Bool
-SyncCheckTriggerNegativeTransition(
- SyncTrigger * /* pTrigger */,
- CARD64 /* oldval */
-);
-
-static Bool
-SyncCheckTriggerPositiveComparison(
- SyncTrigger * /* pTrigger */,
- CARD64 /* oldval */
-);
-
-static Bool
-SyncCheckTriggerPositiveTransition(
- SyncTrigger * /* pTrigger */,
- CARD64 /* oldval */
-);
-
-static SyncCounter *
-SyncCreateCounter(
- ClientPtr /* client */,
- XSyncCounter /* id */,
- CARD64 /* initialvalue */
-);
+static void SyncComputeBracketValues(SyncCounter *, Bool);
-static void SyncComputeBracketValues(
- SyncCounter * /* pCounter */,
- Bool /* startOver */
-);
+static void SyncInitServerTime(void);
-static void
-SyncDeleteTriggerFromCounter(
- SyncTrigger * /* pTrigger */
-);
-
-static Bool
-SyncEventSelectForAlarm(
- SyncAlarm * /* pAlarm */,
- ClientPtr /* client */,
- Bool /* wantevents */
-);
-
-static void
-SyncInitServerTime(
- void
-);
-
-static void
-SyncInitIdleTime(
- void
-);
-
-static void
-SyncResetProc(
- ExtensionEntry * /* extEntry */
-);
-
-static void
-SyncSendAlarmNotifyEvents(
- SyncAlarm * /* pAlarm */
-);
-
-static void
-SyncSendCounterNotifyEvents(
- ClientPtr /* client */,
- SyncAwait ** /* ppAwait */,
- int /* num_events */
-);
+static void SyncInitIdleTime(void);
static DISPATCH_PROC(ProcSyncAwait);
static DISPATCH_PROC(ProcSyncChangeAlarm);
@@ -301,8 +136,7 @@ static DISPATCH_PROC(SProcSyncSetPriority);
* delete and add triggers on this list.
*/
static void
-SyncDeleteTriggerFromCounter(pTrigger)
- SyncTrigger *pTrigger;
+SyncDeleteTriggerFromCounter(SyncTrigger *pTrigger)
{
SyncTriggerList *pCur;
SyncTriggerList *pPrev;
@@ -323,7 +157,7 @@ SyncDeleteTriggerFromCounter(pTrigger)
pPrev->next = pCur->next;
else
pTrigger->pCounter->pTriglist = pCur->next;
-
+
xfree(pCur);
break;
}
@@ -331,15 +165,14 @@ SyncDeleteTriggerFromCounter(pTrigger)
pPrev = pCur;
pCur = pCur->next;
}
-
+
if (IsSystemCounter(pTrigger->pCounter))
SyncComputeBracketValues(pTrigger->pCounter, /*startOver*/ TRUE);
}
static int
-SyncAddTriggerToCounter(pTrigger)
- SyncTrigger *pTrigger;
+SyncAddTriggerToCounter(SyncTrigger *pTrigger)
{
SyncTriggerList *pCur;
@@ -353,7 +186,7 @@ SyncAddTriggerToCounter(pTrigger)
return Success;
}
- if (!(pCur = (SyncTriggerList *)xalloc(sizeof(SyncTriggerList))))
+ if (!(pCur = xalloc(sizeof(SyncTriggerList))))
return BadAlloc;
pCur->pTrigger = pTrigger;
@@ -367,7 +200,7 @@ SyncAddTriggerToCounter(pTrigger)
}
-/* Below are four possible functions that can be plugged into
+/* Below are four possible functions that can be plugged into
* pTrigger->CheckTrigger, corresponding to the four possible
* test-types. These functions are called after the counter's
* value changes but are also passed the old counter value
@@ -377,14 +210,12 @@ SyncAddTriggerToCounter(pTrigger)
* of the trigger.
*
* All of them include the condition pTrigger->pCounter == NULL.
- * This is because the spec says that a trigger with a counter value
+ * This is because the spec says that a trigger with a counter value
* of None is always TRUE.
*/
static Bool
-SyncCheckTriggerPositiveComparison(pTrigger, oldval)
- SyncTrigger *pTrigger;
- CARD64 oldval;
+SyncCheckTriggerPositiveComparison(SyncTrigger *pTrigger, CARD64 oldval)
{
return (pTrigger->pCounter == NULL ||
XSyncValueGreaterOrEqual(pTrigger->pCounter->value,
@@ -392,9 +223,7 @@ SyncCheckTriggerPositiveComparison(pTrigger, oldval)
}
static Bool
-SyncCheckTriggerNegativeComparison(pTrigger, oldval)
- SyncTrigger *pTrigger;
- CARD64 oldval;
+SyncCheckTriggerNegativeComparison(SyncTrigger *pTrigger, CARD64 oldval)
{
return (pTrigger->pCounter == NULL ||
XSyncValueLessOrEqual(pTrigger->pCounter->value,
@@ -402,9 +231,7 @@ SyncCheckTriggerNegativeComparison(pTrigger, oldval)
}
static Bool
-SyncCheckTriggerPositiveTransition(pTrigger, oldval)
- SyncTrigger *pTrigger;
- CARD64 oldval;
+SyncCheckTriggerPositiveTransition(SyncTrigger *pTrigger, CARD64 oldval)
{
return (pTrigger->pCounter == NULL ||
(XSyncValueLessThan(oldval, pTrigger->test_value) &&
@@ -413,9 +240,7 @@ SyncCheckTriggerPositiveTransition(pTrigger, oldval)
}
static Bool
-SyncCheckTriggerNegativeTransition(pTrigger, oldval)
- SyncTrigger *pTrigger;
- CARD64 oldval;
+SyncCheckTriggerNegativeTransition(SyncTrigger *pTrigger, CARD64 oldval)
{
return (pTrigger->pCounter == NULL ||
(XSyncValueGreaterThan(oldval, pTrigger->test_value) &&
@@ -423,14 +248,9 @@ SyncCheckTriggerNegativeTransition(pTrigger, oldval)
pTrigger->test_value)));
}
-
-
-static int
-SyncInitTrigger(client, pTrigger, counter, changes)
- ClientPtr client; /* so we can set errorValue */
- SyncTrigger *pTrigger;
- XSyncCounter counter;
- Mask changes;
+static int
+SyncInitTrigger(ClientPtr client, SyncTrigger *pTrigger, XSyncCounter counter,
+ Mask changes)
{
SyncCounter *pCounter = pTrigger->pCounter;
int rc;
@@ -486,16 +306,16 @@ SyncInitTrigger(client, pTrigger, counter, changes)
switch (pTrigger->test_type)
{
- case XSyncPositiveTransition:
+ case XSyncPositiveTransition:
pTrigger->CheckTrigger = SyncCheckTriggerPositiveTransition;
break;
- case XSyncNegativeTransition:
+ case XSyncNegativeTransition:
pTrigger->CheckTrigger = SyncCheckTriggerNegativeTransition;
break;
- case XSyncPositiveComparison:
+ case XSyncPositiveComparison:
pTrigger->CheckTrigger = SyncCheckTriggerPositiveComparison;
break;
- case XSyncNegativeComparison:
+ case XSyncNegativeComparison:
pTrigger->CheckTrigger = SyncCheckTriggerNegativeComparison;
break;
}
@@ -511,7 +331,7 @@ SyncInitTrigger(client, pTrigger, counter, changes)
if (pCounter == NULL)
return BadMatch;
- XSyncValueAdd(&pTrigger->test_value, pCounter->value,
+ XSyncValueAdd(&pTrigger->test_value, pCounter->value,
pTrigger->wait_value, &overflow);
if (overflow)
{
@@ -533,17 +353,16 @@ SyncInitTrigger(client, pTrigger, counter, changes)
{
SyncComputeBracketValues(pCounter, /*startOver*/ TRUE);
}
-
+
return Success;
}
/* AlarmNotify events happen in response to actions taken on an Alarm or
- * the counter used by the alarm. AlarmNotify may be sent to multiple
+ * the counter used by the alarm. AlarmNotify may be sent to multiple
* clients. The alarm maintains a list of clients interested in events.
*/
static void
-SyncSendAlarmNotifyEvents(pAlarm)
- SyncAlarm *pAlarm;
+SyncSendAlarmNotifyEvents(SyncAlarm *pAlarm)
{
SyncAlarmClientList *pcl;
xSyncAlarmNotifyEvent ane;
@@ -571,7 +390,7 @@ SyncSendAlarmNotifyEvents(pAlarm)
ane.state = pAlarm->state;
/* send to owner */
- if (pAlarm->events && !pAlarm->client->clientGone)
+ if (pAlarm->events && !pAlarm->client->clientGone)
WriteEventsToClient(pAlarm->client, 1, (xEvent *) &ane);
/* send to other interested clients */
@@ -586,23 +405,20 @@ SyncSendAlarmNotifyEvents(pAlarm)
}
-/* CounterNotify events only occur in response to an Await. The events
+/* CounterNotify events only occur in response to an Await. The events
* go only to the Awaiting client.
*/
static void
-SyncSendCounterNotifyEvents(client, ppAwait, num_events)
- ClientPtr client;
- SyncAwait **ppAwait;
- int num_events;
+SyncSendCounterNotifyEvents(ClientPtr client, SyncAwait **ppAwait,
+ int num_events)
{
xSyncCounterNotifyEvent *pEvents, *pev;
int i;
if (client->clientGone)
return;
- pev = pEvents = (xSyncCounterNotifyEvent *)
- xalloc(num_events * sizeof(xSyncCounterNotifyEvent));
- if (!pEvents)
+ pev = pEvents = xalloc(num_events * sizeof(xSyncCounterNotifyEvent));
+ if (!pEvents)
return;
UpdateCurrentTime();
for (i = 0; i < num_events; i++, ppAwait++, pev++)
@@ -629,9 +445,8 @@ SyncSendCounterNotifyEvents(client, ppAwait, num_events)
/* This function is called when an alarm's counter is destroyed.
* It is plugged into pTrigger->CounterDestroyed (for alarm triggers).
*/
-void
-SyncAlarmCounterDestroyed(pTrigger)
- SyncTrigger *pTrigger;
+static void
+SyncAlarmCounterDestroyed(SyncTrigger *pTrigger)
{
SyncAlarm *pAlarm = (SyncAlarm *)pTrigger;
@@ -641,12 +456,11 @@ SyncAlarmCounterDestroyed(pTrigger)
}
-/* This function is called when an alarm "goes off."
+/* This function is called when an alarm "goes off."
* It is plugged into pTrigger->TriggerFired (for alarm triggers).
*/
static void
-SyncAlarmTriggerFired(pTrigger)
- SyncTrigger *pTrigger;
+SyncAlarmTriggerFired(SyncTrigger *pTrigger)
{
SyncAlarm *pAlarm = (SyncAlarm *)pTrigger;
CARD64 new_test_value;
@@ -686,7 +500,7 @@ SyncAlarmTriggerFired(pTrigger)
{
XSyncValueAdd(&paTrigger->test_value, paTrigger->test_value,
pAlarm->delta, &overflow);
- } while (!overflow &&
+ } while (!overflow &&
(*paTrigger->CheckTrigger)(paTrigger,
paTrigger->pCounter->value));
@@ -721,8 +535,7 @@ SyncAlarmTriggerFired(pTrigger)
* (for Await triggers).
*/
static void
-SyncAwaitTriggerFired(pTrigger)
- SyncTrigger *pTrigger;
+SyncAwaitTriggerFired(SyncTrigger *pTrigger)
{
SyncAwait *pAwait = (SyncAwait *)pTrigger;
int numwaits;
@@ -732,7 +545,7 @@ SyncAwaitTriggerFired(pTrigger)
pAwaitUnion = (SyncAwaitUnion *)pAwait->pHeader;
numwaits = pAwaitUnion->header.num_waitconditions;
- ppAwait = (SyncAwait **)xalloc(numwaits * sizeof(SyncAwait *));
+ ppAwait = xalloc(numwaits * sizeof(SyncAwait *));
if (!ppAwait)
goto bail;
@@ -815,9 +628,7 @@ bail:
* any triggers depending on the counter will be checked.
*/
void
-SyncChangeCounter(pCounter, newval)
- SyncCounter *pCounter;
- CARD64 newval;
+SyncChangeCounter(SyncCounter *pCounter, CARD64 newval)
{
SyncTriggerList *ptl, *pnext;
CARD64 oldval;
@@ -842,10 +653,7 @@ SyncChangeCounter(pCounter, newval)
/* loosely based on dix/events.c/EventSelectForWindow */
static Bool
-SyncEventSelectForAlarm(pAlarm, client, wantevents)
- SyncAlarm *pAlarm;
- ClientPtr client;
- Bool wantevents;
+SyncEventSelectForAlarm(SyncAlarm *pAlarm, ClientPtr client, Bool wantevents)
{
SyncAlarmClientList *pClients;
@@ -862,8 +670,8 @@ SyncEventSelectForAlarm(pAlarm, client, wantevents)
{
if (pClients->client == client)
{
- /* client's presence on the list indicates desire for
- * events. If the client doesn't want events, remove it
+ /* client's presence on the list indicates desire for
+ * events. If the client doesn't want events, remove it
* from the list. If the client does want events, do
* nothing, since it's already got them.
*/
@@ -880,18 +688,18 @@ SyncEventSelectForAlarm(pAlarm, client, wantevents)
*/
if (!wantevents)
- /* client doesn't want events, and we just discovered that it
+ /* client doesn't want events, and we just discovered that it
* doesn't have them, so there's nothing to do.
*/
return Success;
/* add new client to pAlarm->pEventClients */
- pClients = (SyncAlarmClientList *) xalloc(sizeof(SyncAlarmClientList));
+ pClients = xalloc(sizeof(SyncAlarmClientList));
if (!pClients)
return BadAlloc;
- /* register it as a resource so it will be cleaned up
+ /* register it as a resource so it will be cleaned up
* if the client dies
*/
@@ -913,12 +721,9 @@ SyncEventSelectForAlarm(pAlarm, client, wantevents)
/*
* ** SyncChangeAlarmAttributes ** This is used by CreateAlarm and ChangeAlarm
*/
-static int
-SyncChangeAlarmAttributes(client, pAlarm, mask, values)
- ClientPtr client;
- SyncAlarm *pAlarm;
- Mask mask;
- CARD32 *values;
+static int
+SyncChangeAlarmAttributes(ClientPtr client, SyncAlarm *pAlarm, Mask mask,
+ CARD32 *values)
{
int status;
XSyncCounter counter;
@@ -1015,20 +820,17 @@ SyncChangeAlarmAttributes(client, pAlarm, mask, values)
static SyncCounter *
-SyncCreateCounter(client, id, initialvalue)
- ClientPtr client;
- XSyncCounter id;
- CARD64 initialvalue;
+SyncCreateCounter(ClientPtr client, XSyncCounter id, CARD64 initialvalue)
{
SyncCounter *pCounter;
- if (!(pCounter = (SyncCounter *) xalloc(sizeof(SyncCounter))))
- return (SyncCounter *)NULL;
+ if (!(pCounter = xalloc(sizeof(SyncCounter))))
+ return NULL;
if (!AddResource(id, RTCounter, (pointer) pCounter))
{
- xfree((pointer) pCounter);
- return (SyncCounter *)NULL;
+ xfree(pCounter);
+ return NULL;
}
pCounter->client = client;
@@ -1040,36 +842,31 @@ SyncCreateCounter(client, id, initialvalue)
return pCounter;
}
-static int FreeCounter(
- pointer /*env*/,
- XID /*id*/
-);
+static int FreeCounter(void *, XID);
/*
* ***** System Counter utilities
*/
-pointer
-SyncCreateSystemCounter(name, initial, resolution, counterType,
- QueryValue, BracketValues)
- char *name;
- CARD64 initial;
- CARD64 resolution;
- SyncCounterType counterType;
- void (*QueryValue) (
- pointer /* pCounter */,
- CARD64 * /* pValue_return */);
- void (*BracketValues) (
- pointer /* pCounter */,
- CARD64 * /* pbracket_less */,
- CARD64 * /* pbracket_greater */);
+pointer
+SyncCreateSystemCounter(
+ char *name,
+ CARD64 initial,
+ CARD64 resolution,
+ SyncCounterType counterType,
+ void (*QueryValue)(pointer /* pCounter */,
+ CARD64 * /* pValue_return */),
+ void (*BracketValues)(pointer /* pCounter */,
+ CARD64 * /* pbracket_less */,
+ CARD64 * /* pbracket_greater */)
+ )
{
SyncCounter *pCounter;
- SysCounterList = (SyncCounter **)xrealloc(SysCounterList,
+ SysCounterList = xrealloc(SysCounterList,
(SyncNumSystemCounters+1)*sizeof(SyncCounter *));
if (!SysCounterList)
- return (pointer)NULL;
+ return NULL;
/* this function may be called before SYNC has been initialized, so we
* have to make sure RTCounter is created.
@@ -1079,21 +876,21 @@ SyncCreateSystemCounter(name, initial, resolution, counterType,
RTCounter = CreateNewResourceType(FreeCounter);
if (RTCounter == 0)
{
- return (pointer)NULL;
+ return NULL;
}
}
- pCounter = SyncCreateCounter((ClientPtr)NULL, FakeClientID(0), initial);
+ pCounter = SyncCreateCounter(NULL, FakeClientID(0), initial);
if (pCounter)
{
SysCounterInfo *psci;
- psci = (SysCounterInfo *)xalloc(sizeof(SysCounterInfo));
+ psci = xalloc(sizeof(SysCounterInfo));
if (!psci)
{
FreeResource(pCounter->id, RT_NONE);
- return (pointer) pCounter;
+ return pCounter;
}
pCounter->pSysCounterInfo = psci;
psci->name = name;
@@ -1105,21 +902,18 @@ SyncCreateSystemCounter(name, initial, resolution, counterType,
XSyncMinValue(&psci->bracket_less);
SysCounterList[SyncNumSystemCounters++] = pCounter;
}
- return (pointer) pCounter;
+ return pCounter;
}
void
-SyncDestroySystemCounter(pSysCounter)
- pointer pSysCounter;
+SyncDestroySystemCounter(pointer pSysCounter)
{
SyncCounter *pCounter = (SyncCounter *)pSysCounter;
FreeResource(pCounter->id, RT_NONE);
}
static void
-SyncComputeBracketValues(pCounter, startOver)
- SyncCounter *pCounter;
- Bool startOver;
+SyncComputeBracketValues(SyncCounter *pCounter, Bool startOver)
{
SyncTriggerList *pCur;
SyncTrigger *pTrigger;
@@ -1202,9 +996,7 @@ SyncComputeBracketValues(pCounter, startOver)
/* ARGSUSED */
static int
-FreeAlarm(addr, id)
- pointer addr;
- XID id;
+FreeAlarm(void *addr, XID id)
{
SyncAlarm *pAlarm = (SyncAlarm *) addr;
@@ -1229,9 +1021,7 @@ FreeAlarm(addr, id)
*/
/* ARGSUSED */
static int
-FreeCounter(env, id)
- pointer env;
- XID id;
+FreeCounter(void *env, XID id)
{
SyncCounter *pCounter = (SyncCounter *) env;
SyncTriggerList *ptl, *pnext;
@@ -1281,9 +1071,7 @@ FreeCounter(env, id)
*/
/* ARGSUSED */
static int
-FreeAwait(addr, id)
- pointer addr;
- XID id;
+FreeAwait(void *addr, XID id)
{
SyncAwaitUnion *pAwaitUnion = (SyncAwaitUnion *) addr;
SyncAwait *pAwait;
@@ -1296,7 +1084,7 @@ FreeAwait(addr, id)
for (numwaits = pAwaitUnion->header.num_waitconditions; numwaits;
numwaits--, pAwait++)
{
- /* If the counter is being destroyed, FreeCounter will delete
+ /* If the counter is being destroyed, FreeCounter will delete
* the trigger list itself, so don't do it here.
*/
SyncCounter *pCounter = pAwait->trigger.pCounter;
@@ -1309,9 +1097,7 @@ FreeAwait(addr, id)
/* loosely based on dix/events.c/OtherClientGone */
static int
-FreeAlarmClient(value, id)
- pointer value; /* must conform to DeleteType */
- XID id;
+FreeAlarmClient(void *value, XID id)
{
SyncAlarm *pAlarm = (SyncAlarm *)value;
SyncAlarmClientList *pCur, *pPrev;
@@ -1327,7 +1113,7 @@ FreeAlarmClient(value, id)
else
pAlarm->pEventClients = pCur->next;
xfree(pCur);
- return(Success);
+ return Success;
}
}
FatalError("alarm client not on event list");
@@ -1343,15 +1129,15 @@ FreeAlarmClient(value, id)
/*
* ** Initialize the extension
*/
-static int
-ProcSyncInitialize(client)
- ClientPtr client;
+static int
+ProcSyncInitialize(ClientPtr client)
{
xSyncInitializeReply rep;
int n;
REQUEST_SIZE_MATCH(xSyncInitializeReq);
+ memset(&rep, 0, sizeof(xSyncInitializeReply));
rep.type = X_Reply;
rep.sequenceNumber = client->sequence;
rep.majorVersion = SYNC_MAJOR_VERSION;
@@ -1363,20 +1149,19 @@ ProcSyncInitialize(client)
swaps(&rep.sequenceNumber, n);
}
WriteToClient(client, sizeof(rep), (char *) &rep);
- return (client->noClientException);
+ return client->noClientException;
}
/*
* ** Get list of system counters available through the extension
*/
-static int
-ProcSyncListSystemCounters(client)
- ClientPtr client;
+static int
+ProcSyncListSystemCounters(ClientPtr client)
{
xSyncListSystemCountersReply rep;
int i, len;
xSyncSystemCounter *list = NULL, *walklist = NULL;
-
+
REQUEST_SIZE_MATCH(xSyncListSystemCountersReq);
rep.type = X_Reply;
@@ -1387,17 +1172,17 @@ ProcSyncListSystemCounters(client)
{
char *name = SysCounterList[i]->pSysCounterInfo->name;
/* pad to 4 byte boundary */
- len += (sz_xSyncSystemCounter + strlen(name) + 3) & ~3;
+ len += pad_to_int32(sz_xSyncSystemCounter + strlen(name));
}
if (len)
{
- walklist = list = (xSyncSystemCounter *) xalloc(len);
+ walklist = list = xalloc(len);
if (!list)
return BadAlloc;
}
- rep.length = len >> 2;
+ rep.length = bytes_to_int32(len);
if (client->swapped)
{
@@ -1430,26 +1215,25 @@ ProcSyncListSystemCounters(client)
pname_in_reply = ((char *)walklist) + sz_xSyncSystemCounter;
strncpy(pname_in_reply, psci->name, namelen);
- walklist = (xSyncSystemCounter *) (((char *)walklist) +
- ((sz_xSyncSystemCounter + namelen + 3) & ~3));
+ walklist = (xSyncSystemCounter *) (((char *)walklist) +
+ pad_to_int32(sz_xSyncSystemCounter + namelen));
}
WriteToClient(client, sizeof(rep), (char *) &rep);
- if (len)
+ if (len)
{
WriteToClient(client, len, (char *) list);
xfree(list);
}
- return (client->noClientException);
+ return client->noClientException;
}
/*
* ** Set client Priority
*/
-static int
-ProcSyncSetPriority(client)
- ClientPtr client;
+static int
+ProcSyncSetPriority(ClientPtr client)
{
REQUEST(xSyncSetPriorityReq);
ClientPtr priorityclient;
@@ -1483,9 +1267,8 @@ ProcSyncSetPriority(client)
/*
* ** Get client Priority
*/
-static int
-ProcSyncGetPriority(client)
- ClientPtr client;
+static int
+ProcSyncGetPriority(ClientPtr client)
{
REQUEST(xSyncGetPriorityReq);
xSyncGetPriorityReply rep;
@@ -1517,15 +1300,14 @@ ProcSyncGetPriority(client)
WriteToClient(client, sizeof(xSyncGetPriorityReply), (char *) &rep);
- return (client->noClientException);
+ return client->noClientException;
}
/*
* ** Create a new counter
*/
-static int
-ProcSyncCreateCounter(client)
- ClientPtr client;
+static int
+ProcSyncCreateCounter(ClientPtr client)
{
REQUEST(xSyncCreateCounterReq);
CARD64 initial;
@@ -1538,29 +1320,26 @@ ProcSyncCreateCounter(client)
if (!SyncCreateCounter(client, stuff->cid, initial))
return BadAlloc;
- return (client->noClientException);
+ return client->noClientException;
}
/*
* ** Set Counter value
*/
-static int
-ProcSyncSetCounter(client)
- ClientPtr client;
+static int
+ProcSyncSetCounter(ClientPtr client)
{
REQUEST(xSyncSetCounterReq);
SyncCounter *pCounter;
CARD64 newvalue;
+ int rc;
REQUEST_SIZE_MATCH(xSyncSetCounterReq);
- pCounter = (SyncCounter *)SecurityLookupIDByType(client, stuff->cid,
- RTCounter, DixWriteAccess);
- if (pCounter == NULL)
- {
- client->errorValue = stuff->cid;
- return SyncErrorBase + XSyncBadCounter;
- }
+ rc = dixLookupResourceByType((pointer *)&pCounter, stuff->cid, RTCounter,
+ client, DixWriteAccess);
+ if (rc != Success)
+ return (rc == BadValue) ? SyncErrorBase + XSyncBadCounter : rc;
if (IsSystemCounter(pCounter))
{
@@ -1576,24 +1355,21 @@ ProcSyncSetCounter(client)
/*
* ** Change Counter value
*/
-static int
-ProcSyncChangeCounter(client)
- ClientPtr client;
+static int
+ProcSyncChangeCounter(ClientPtr client)
{
REQUEST(xSyncChangeCounterReq);
SyncCounter *pCounter;
CARD64 newvalue;
Bool overflow;
+ int rc;
REQUEST_SIZE_MATCH(xSyncChangeCounterReq);
- pCounter = (SyncCounter *) SecurityLookupIDByType(client, stuff->cid,
- RTCounter, DixWriteAccess);
- if (pCounter == NULL)
- {
- client->errorValue = stuff->cid;
- return SyncErrorBase + XSyncBadCounter;
- }
+ rc = dixLookupResourceByType((pointer *)&pCounter, stuff->cid, RTCounter,
+ client, DixWriteAccess);
+ if (rc != Success)
+ return (rc == BadValue) ? SyncErrorBase + XSyncBadCounter : rc;
if (IsSystemCounter(pCounter))
{
@@ -1606,7 +1382,7 @@ ProcSyncChangeCounter(client)
if (overflow)
{
/* XXX 64 bit value can't fit in 32 bits; do the best we can */
- client->errorValue = stuff->value_hi;
+ client->errorValue = stuff->value_hi;
return BadValue;
}
SyncChangeCounter(pCounter, newvalue);
@@ -1616,22 +1392,20 @@ ProcSyncChangeCounter(client)
/*
* ** Destroy a counter
*/
-static int
-ProcSyncDestroyCounter(client)
- ClientPtr client;
+static int
+ProcSyncDestroyCounter(ClientPtr client)
{
REQUEST(xSyncDestroyCounterReq);
SyncCounter *pCounter;
+ int rc;
REQUEST_SIZE_MATCH(xSyncDestroyCounterReq);
- pCounter = (SyncCounter *)SecurityLookupIDByType(client, stuff->counter,
- RTCounter, DixDestroyAccess);
- if (pCounter == NULL)
- {
- client->errorValue = stuff->counter;
- return SyncErrorBase + XSyncBadCounter;
- }
+ rc = dixLookupResourceByType((pointer *)&pCounter, stuff->counter, RTCounter,
+ client, DixDestroyAccess);
+ if (rc != Success)
+ return (rc == BadValue) ? SyncErrorBase + XSyncBadCounter : rc;
+
if (IsSystemCounter(pCounter))
{
client->errorValue = stuff->counter;
@@ -1645,9 +1419,8 @@ ProcSyncDestroyCounter(client)
/*
* ** Await
*/
-static int
-ProcSyncAwait(client)
- ClientPtr client;
+static int
+ProcSyncAwait(ClientPtr client)
{
REQUEST(xSyncAwaitReq);
int len, items;
@@ -1675,10 +1448,10 @@ ProcSyncAwait(client)
pProtocolWaitConds = (xSyncWaitCondition *) & stuff[1];
- /* all the memory for the entire await list is allocated
+ /* all the memory for the entire await list is allocated
* here in one chunk
*/
- pAwaitUnion = (SyncAwaitUnion *)xalloc((items+1) * sizeof(SyncAwaitUnion));
+ pAwaitUnion = xalloc((items+1) * sizeof(SyncAwaitUnion));
if (!pAwaitUnion)
return BadAlloc;
@@ -1761,23 +1534,20 @@ ProcSyncAwait(client)
/*
* ** Query a counter
*/
-static int
-ProcSyncQueryCounter(client)
- ClientPtr client;
+static int
+ProcSyncQueryCounter(ClientPtr client)
{
REQUEST(xSyncQueryCounterReq);
xSyncQueryCounterReply rep;
SyncCounter *pCounter;
+ int rc;
REQUEST_SIZE_MATCH(xSyncQueryCounterReq);
- pCounter = (SyncCounter *)SecurityLookupIDByType(client, stuff->counter,
- RTCounter, DixReadAccess);
- if (pCounter == NULL)
- {
- client->errorValue = stuff->counter;
- return SyncErrorBase + XSyncBadCounter;
- }
+ rc = dixLookupResourceByType((pointer *)&pCounter, stuff->counter,
+ RTCounter, client, DixReadAccess);
+ if (rc != Success)
+ return (rc == BadValue) ? SyncErrorBase + XSyncBadCounter : rc;
rep.type = X_Reply;
rep.length = 0;
@@ -1802,16 +1572,15 @@ ProcSyncQueryCounter(client)
swapl(&rep.value_lo, n);
}
WriteToClient(client, sizeof(xSyncQueryCounterReply), (char *) &rep);
- return (client->noClientException);
+ return client->noClientException;
}
/*
* ** Create Alarm
*/
-static int
-ProcSyncCreateAlarm(client)
- ClientPtr client;
+static int
+ProcSyncCreateAlarm(ClientPtr client)
{
REQUEST(xSyncCreateAlarmReq);
SyncAlarm *pAlarm;
@@ -1824,12 +1593,12 @@ ProcSyncCreateAlarm(client)
LEGAL_NEW_RESOURCE(stuff->id, client);
vmask = stuff->valueMask;
- len = client->req_len - (sizeof(xSyncCreateAlarmReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xSyncCreateAlarmReq));
/* the "extra" call to Ones accounts for the presence of 64 bit values */
if (len != (Ones(vmask) + Ones(vmask & (XSyncCAValue|XSyncCADelta))))
return BadLength;
- if (!(pAlarm = (SyncAlarm *) xalloc(sizeof(SyncAlarm))))
+ if (!(pAlarm = xalloc(sizeof(SyncAlarm))))
{
return BadAlloc;
}
@@ -1889,9 +1658,8 @@ ProcSyncCreateAlarm(client)
/*
* ** Change Alarm
*/
-static int
-ProcSyncChangeAlarm(client)
- ClientPtr client;
+static int
+ProcSyncChangeAlarm(ClientPtr client)
{
REQUEST(xSyncChangeAlarmReq);
SyncAlarm *pAlarm;
@@ -1900,20 +1668,18 @@ ProcSyncChangeAlarm(client)
REQUEST_AT_LEAST_SIZE(xSyncChangeAlarmReq);
- if (!(pAlarm = (SyncAlarm *)SecurityLookupIDByType(client, stuff->alarm,
- RTAlarm, DixWriteAccess)))
- {
- client->errorValue = stuff->alarm;
- return SyncErrorBase + XSyncBadAlarm;
- }
+ status = dixLookupResourceByType((pointer *)&pAlarm, stuff->alarm, RTAlarm,
+ client, DixWriteAccess);
+ if (status != Success)
+ return (status == BadValue) ? SyncErrorBase + XSyncBadAlarm : status;
vmask = stuff->valueMask;
- len = client->req_len - (sizeof(xSyncChangeAlarmReq) >> 2);
+ len = client->req_len - bytes_to_int32(sizeof(xSyncChangeAlarmReq));
/* the "extra" call to Ones accounts for the presence of 64 bit values */
if (len != (Ones(vmask) + Ones(vmask & (XSyncCAValue|XSyncCADelta))))
return BadLength;
- if ((status = SyncChangeAlarmAttributes(client, pAlarm, vmask,
+ if ((status = SyncChangeAlarmAttributes(client, pAlarm, vmask,
(CARD32 *)&stuff[1])) != Success)
return status;
@@ -1930,27 +1696,24 @@ ProcSyncChangeAlarm(client)
return Success;
}
-static int
-ProcSyncQueryAlarm(client)
- ClientPtr client;
+static int
+ProcSyncQueryAlarm(ClientPtr client)
{
REQUEST(xSyncQueryAlarmReq);
SyncAlarm *pAlarm;
xSyncQueryAlarmReply rep;
SyncTrigger *pTrigger;
+ int rc;
REQUEST_SIZE_MATCH(xSyncQueryAlarmReq);
- pAlarm = (SyncAlarm *)SecurityLookupIDByType(client, stuff->alarm,
- RTAlarm, DixReadAccess);
- if (!pAlarm)
- {
- client->errorValue = stuff->alarm;
- return (SyncErrorBase + XSyncBadAlarm);
- }
+ rc = dixLookupResourceByType((pointer *)&pAlarm, stuff->alarm, RTAlarm,
+ client, DixReadAccess);
+ if (rc != Success)
+ return (rc == BadValue) ? SyncErrorBase + XSyncBadAlarm : rc;
rep.type = X_Reply;
- rep.length = (sizeof(xSyncQueryAlarmReply) - sizeof(xGenericReply)) >> 2;
+ rep.length = bytes_to_int32(sizeof(xSyncQueryAlarmReply) - sizeof(xGenericReply));
rep.sequenceNumber = client->sequence;
pTrigger = &pAlarm->trigger;
@@ -1989,41 +1752,37 @@ ProcSyncQueryAlarm(client)
}
WriteToClient(client, sizeof(xSyncQueryAlarmReply), (char *) &rep);
- return (client->noClientException);
+ return client->noClientException;
}
-
-static int
-ProcSyncDestroyAlarm(client)
- ClientPtr client;
+static int
+ProcSyncDestroyAlarm(ClientPtr client)
{
+ SyncAlarm *pAlarm;
+ int rc;
REQUEST(xSyncDestroyAlarmReq);
REQUEST_SIZE_MATCH(xSyncDestroyAlarmReq);
- if (!((SyncAlarm *)SecurityLookupIDByType(client, stuff->alarm,
- RTAlarm, DixDestroyAccess)))
- {
- client->errorValue = stuff->alarm;
- return SyncErrorBase + XSyncBadAlarm;
- }
+ rc = dixLookupResourceByType((pointer *)&pAlarm, stuff->alarm, RTAlarm,
+ client, DixDestroyAccess);
+ if (rc != Success)
+ return (rc == BadValue) ? SyncErrorBase + XSyncBadAlarm : rc;
FreeResource(stuff->alarm, RT_NONE);
- return (client->noClientException);
+ return client->noClientException;
}
/*
* ** Given an extension request, call the appropriate request procedure
*/
-static int
-ProcSyncDispatch(client)
- ClientPtr client;
+static int
+ProcSyncDispatch(ClientPtr client)
{
REQUEST(xReq);
switch (stuff->data)
{
-
case X_SyncInitialize:
return ProcSyncInitialize(client);
case X_SyncListSystemCounters:
@@ -2061,9 +1820,8 @@ ProcSyncDispatch(client)
* Boring Swapping stuff ...
*/
-static int
-SProcSyncInitialize(client)
- ClientPtr client;
+static int
+SProcSyncInitialize(ClientPtr client)
{
REQUEST(xSyncInitializeReq);
char n;
@@ -2074,9 +1832,8 @@ SProcSyncInitialize(client)
return ProcSyncInitialize(client);
}
-static int
-SProcSyncListSystemCounters(client)
- ClientPtr client;
+static int
+SProcSyncListSystemCounters(ClientPtr client)
{
REQUEST(xSyncListSystemCountersReq);
char n;
@@ -2087,9 +1844,8 @@ SProcSyncListSystemCounters(client)
return ProcSyncListSystemCounters(client);
}
-static int
-SProcSyncCreateCounter(client)
- ClientPtr client;
+static int
+SProcSyncCreateCounter(ClientPtr client)
{
REQUEST(xSyncCreateCounterReq);
char n;
@@ -2103,9 +1859,8 @@ SProcSyncCreateCounter(client)
return ProcSyncCreateCounter(client);
}
-static int
-SProcSyncSetCounter(client)
- ClientPtr client;
+static int
+SProcSyncSetCounter(ClientPtr client)
{
REQUEST(xSyncSetCounterReq);
char n;
@@ -2119,9 +1874,8 @@ SProcSyncSetCounter(client)
return ProcSyncSetCounter(client);
}
-static int
-SProcSyncChangeCounter(client)
- ClientPtr client;
+static int
+SProcSyncChangeCounter(ClientPtr client)
{
REQUEST(xSyncChangeCounterReq);
char n;
@@ -2135,9 +1889,8 @@ SProcSyncChangeCounter(client)
return ProcSyncChangeCounter(client);
}
-static int
-SProcSyncQueryCounter(client)
- ClientPtr client;
+static int
+SProcSyncQueryCounter(ClientPtr client)
{
REQUEST(xSyncQueryCounterReq);
char n;
@@ -2149,9 +1902,8 @@ SProcSyncQueryCounter(client)
return ProcSyncQueryCounter(client);
}
-static int
-SProcSyncDestroyCounter(client)
- ClientPtr client;
+static int
+SProcSyncDestroyCounter(ClientPtr client)
{
REQUEST(xSyncDestroyCounterReq);
char n;
@@ -2163,9 +1915,8 @@ SProcSyncDestroyCounter(client)
return ProcSyncDestroyCounter(client);
}
-static int
-SProcSyncAwait(client)
- ClientPtr client;
+static int
+SProcSyncAwait(ClientPtr client)
{
REQUEST(xSyncAwaitReq);
char n;
@@ -2177,10 +1928,8 @@ SProcSyncAwait(client)
return ProcSyncAwait(client);
}
-
-static int
-SProcSyncCreateAlarm(client)
- ClientPtr client;
+static int
+SProcSyncCreateAlarm(ClientPtr client)
{
REQUEST(xSyncCreateAlarmReq);
char n;
@@ -2194,9 +1943,8 @@ SProcSyncCreateAlarm(client)
return ProcSyncCreateAlarm(client);
}
-static int
-SProcSyncChangeAlarm(client)
- ClientPtr client;
+static int
+SProcSyncChangeAlarm(ClientPtr client)
{
REQUEST(xSyncChangeAlarmReq);
char n;
@@ -2209,9 +1957,8 @@ SProcSyncChangeAlarm(client)
return ProcSyncChangeAlarm(client);
}
-static int
-SProcSyncQueryAlarm(client)
- ClientPtr client;
+static int
+SProcSyncQueryAlarm(ClientPtr client)
{
REQUEST(xSyncQueryAlarmReq);
char n;
@@ -2223,9 +1970,8 @@ SProcSyncQueryAlarm(client)
return ProcSyncQueryAlarm(client);
}
-static int
-SProcSyncDestroyAlarm(client)
- ClientPtr client;
+static int
+SProcSyncDestroyAlarm(ClientPtr client)
{
REQUEST(xSyncDestroyAlarmReq);
char n;
@@ -2237,9 +1983,8 @@ SProcSyncDestroyAlarm(client)
return ProcSyncDestroyAlarm(client);
}
-static int
-SProcSyncSetPriority(client)
- ClientPtr client;
+static int
+SProcSyncSetPriority(ClientPtr client)
{
REQUEST(xSyncSetPriorityReq);
char n;
@@ -2252,9 +1997,8 @@ SProcSyncSetPriority(client)
return ProcSyncSetPriority(client);
}
-static int
-SProcSyncGetPriority(client)
- ClientPtr client;
+static int
+SProcSyncGetPriority(ClientPtr client)
{
REQUEST(xSyncGetPriorityReq);
char n;
@@ -2267,9 +2011,8 @@ SProcSyncGetPriority(client)
}
-static int
-SProcSyncDispatch(client)
- ClientPtr client;
+static int
+SProcSyncDispatch(ClientPtr client)
{
REQUEST(xReq);
@@ -2312,9 +2055,8 @@ SProcSyncDispatch(client)
* Event Swapping
*/
-static void
-SCounterNotifyEvent(from, to)
- xSyncCounterNotifyEvent *from, *to;
+static void
+SCounterNotifyEvent(xSyncCounterNotifyEvent *from, xSyncCounterNotifyEvent *to)
{
to->type = from->type;
to->kind = from->kind;
@@ -2330,9 +2072,8 @@ SCounterNotifyEvent(from, to)
}
-static void
-SAlarmNotifyEvent(from, to)
- xSyncAlarmNotifyEvent *from, *to;
+static void
+SAlarmNotifyEvent(xSyncAlarmNotifyEvent *from, xSyncAlarmNotifyEvent *to)
{
to->type = from->type;
to->kind = from->kind;
@@ -2350,9 +2091,8 @@ SAlarmNotifyEvent(from, to)
* ** Close everything down. ** This is fairly simple for now.
*/
/* ARGSUSED */
-static void
-SyncResetProc(extEntry)
- ExtensionEntry *extEntry;
+static void
+SyncResetProc(ExtensionEntry *extEntry)
{
xfree(SysCounterList);
SysCounterList = NULL;
@@ -2363,8 +2103,8 @@ SyncResetProc(extEntry)
/*
* ** Initialise the extension.
*/
-void
-SyncExtensionInit(INITARGS)
+void
+SyncExtensionInit(void)
{
ExtensionEntry *extEntry;
@@ -2433,10 +2173,8 @@ static XSyncValue *pnext_time;
*** code inspired by multibuffer extension
*/
/*ARGSUSED*/
-static void ServertimeBlockHandler(env, wt, LastSelectMask)
-pointer env;
-struct timeval **wt;
-pointer LastSelectMask;
+static void
+ServertimeBlockHandler(void *env, struct timeval **wt, void *LastSelectMask)
{
XSyncValue delay;
unsigned long timeout;
@@ -2448,7 +2186,7 @@ pointer LastSelectMask;
if (XSyncValueGreaterOrEqual(Now, *pnext_time))
{
timeout = 0;
- }
+ }
else
{
Bool overflow;
@@ -2464,10 +2202,8 @@ pointer LastSelectMask;
*** Wakeup Handler
*/
/*ARGSUSED*/
-static void ServertimeWakeupHandler(env, rc, LastSelectMask)
-pointer env;
-int rc;
-pointer LastSelectMask;
+static void
+ServertimeWakeupHandler(void *env, int rc, void *LastSelectMask)
{
if (pnext_time)
{
@@ -2481,19 +2217,15 @@ pointer LastSelectMask;
}
static void
-ServertimeQueryValue(pCounter, pValue_return)
- pointer pCounter;
- CARD64 *pValue_return;
+ServertimeQueryValue(void *pCounter, CARD64 *pValue_return)
{
GetTime();
*pValue_return = Now;
}
static void
-ServertimeBracketValues(pCounter, pbracket_less, pbracket_greater)
- pointer pCounter;
- CARD64 *pbracket_less;
- CARD64 *pbracket_greater;
+ServertimeBracketValues(void *pCounter, CARD64 *pbracket_less,
+ CARD64 *pbracket_greater)
{
if (!pnext_time && pbracket_greater)
{
@@ -2607,9 +2339,7 @@ IdleTimeBlockHandler(pointer env, struct timeval **wt, pointer LastSelectMask)
}
static void
-IdleTimeWakeupHandler (pointer env,
- int rc,
- pointer LastSelectMask)
+IdleTimeWakeupHandler (pointer env, int rc, pointer LastSelectMask)
{
XSyncValue idle;
@@ -2628,8 +2358,7 @@ IdleTimeWakeupHandler (pointer env,
}
static void
-IdleTimeBracketValues (pointer pCounter,
- CARD64 *pbracket_less,
+IdleTimeBracketValues (pointer pCounter, CARD64 *pbracket_less,
CARD64 *pbracket_greater)
{
Bool registered = (pIdleTimeValueLess || pIdleTimeValueGreater);