summaryrefslogtreecommitdiff
path: root/Xext/sync.c
diff options
context:
space:
mode:
authorIan Romanick <idr@us.ibm.com>2007-06-18 16:51:13 -0700
committerIan Romanick <idr@us.ibm.com>2007-06-18 16:51:13 -0700
commitab7a6d860d4a275a810a64b1ba7b13726ed10575 (patch)
tree1198628dab08c3989dff073b4bbe6920a1feca59 /Xext/sync.c
parente9130b8bac73a0843d5ff6b2216eccfb3e094a48 (diff)
parent2e7fef7d0837939e822c40b6ac77e7f0e66d57bd (diff)
Merge branch 'master' of git+ssh://git.freedesktop.org/git/xorg/xserver into pci-rework
Conflicts: hw/xfree86/os-support/bus/Pci.c hw/xfree86/os-support/bus/linuxPci.c
Diffstat (limited to 'Xext/sync.c')
-rw-r--r--Xext/sync.c121
1 files changed, 120 insertions, 1 deletions
diff --git a/Xext/sync.c b/Xext/sync.c
index 531b48cc1..6fc2dcc7c 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -243,6 +243,11 @@ SyncInitServerTime(
void
);
+static void
+SyncInitIdleTime(
+ void
+);
+
static void
SyncResetProc(
ExtensionEntry * /* extEntry */
@@ -2400,6 +2405,7 @@ SyncExtensionInit(INITARGS)
* because there is always a servertime counter.
*/
SyncInitServerTime();
+ SyncInitIdleTime();
#ifdef DEBUG
fprintf(stderr, "Sync Extension %d.%d\n",
@@ -2509,7 +2515,7 @@ ServertimeBracketValues(pCounter, pbracket_less, pbracket_greater)
}
static void
-SyncInitServerTime()
+SyncInitServerTime(void)
{
CARD64 resolution;
@@ -2520,3 +2526,116 @@ SyncInitServerTime()
ServertimeQueryValue, ServertimeBracketValues);
pnext_time = NULL;
}
+
+
+
+/*
+ * IDLETIME implementation
+ */
+
+static pointer IdleTimeCounter;
+static XSyncValue *pIdleTimeValueLess;
+static XSyncValue *pIdleTimeValueGreater;
+
+static void
+IdleTimeQueryValue (pointer pCounter, CARD64 *pValue_return)
+{
+ CARD32 idle = GetTimeInMillis() - lastDeviceEventTime.milliseconds;
+ XSyncIntsToValue (pValue_return, idle, 0);
+}
+
+static void
+IdleTimeBlockHandler (pointer env,
+ struct timeval **wt,
+ pointer LastSelectMask)
+{
+ XSyncValue idle;
+
+ if (!pIdleTimeValueLess && !pIdleTimeValueGreater)
+ return;
+
+ IdleTimeQueryValue (NULL, &idle);
+
+ if (pIdleTimeValueLess &&
+ XSyncValueLessOrEqual (idle, *pIdleTimeValueLess))
+ {
+ AdjustWaitForDelay (wt, 0);
+ }
+ else if (pIdleTimeValueGreater)
+ {
+ unsigned long timeout = 0;
+
+ if (XSyncValueLessThan (idle, *pIdleTimeValueGreater))
+ {
+ XSyncValue value;
+ Bool overflow;
+
+ XSyncValueSubtract (&value, *pIdleTimeValueGreater,
+ idle, &overflow);
+ timeout = XSyncValueLow32 (value);
+ }
+
+ AdjustWaitForDelay (wt, timeout);
+ }
+}
+
+static void
+IdleTimeWakeupHandler (pointer env,
+ int rc,
+ pointer LastSelectMask)
+{
+ XSyncValue idle;
+
+ if (!pIdleTimeValueLess && !pIdleTimeValueGreater)
+ return;
+
+ IdleTimeQueryValue (NULL, &idle);
+
+ if ((pIdleTimeValueGreater &&
+ XSyncValueGreaterThan (idle, *pIdleTimeValueGreater)) ||
+ (pIdleTimeValueLess && XSyncValueLessThan (idle, *pIdleTimeValueLess)))
+ {
+ SyncChangeCounter (IdleTimeCounter, idle);
+ }
+}
+
+static void
+IdleTimeBracketValues (pointer pCounter,
+ CARD64 *pbracket_less,
+ CARD64 *pbracket_greater)
+{
+ Bool registered = (pIdleTimeValueLess || pIdleTimeValueGreater);
+
+ if (registered && !pbracket_less && !pbracket_greater)
+ {
+ RemoveBlockAndWakeupHandlers(IdleTimeBlockHandler,
+ IdleTimeWakeupHandler,
+ NULL);
+ }
+ else if (!registered && (pbracket_less || pbracket_greater))
+ {
+ RegisterBlockAndWakeupHandlers(IdleTimeBlockHandler,
+ IdleTimeWakeupHandler,
+ NULL);
+ }
+
+ pIdleTimeValueGreater = pbracket_greater;
+ pIdleTimeValueLess = pbracket_less;
+}
+
+static void
+SyncInitIdleTime (void)
+{
+ CARD64 resolution;
+ XSyncValue idle;
+
+ IdleTimeQueryValue (NULL, &idle);
+ XSyncIntToValue (&resolution, 4);
+
+ IdleTimeCounter = SyncCreateSystemCounter ("IDLETIME", idle, resolution,
+ XSyncCounterUnrestricted,
+ IdleTimeQueryValue,
+ IdleTimeBracketValues);
+
+ pIdleTimeValueLess = pIdleTimeValueGreater = NULL;
+}