[PATCH v2 6/9] Xext: store the bracket values for idle counters in the private

Peter Hutterer peter.hutterer at who-t.net
Wed Mar 14 21:10:27 PDT 2012


And drop the three global variables, we have a reference to the counter
everywhere now.

Signed-off-by: Peter Hutterer <peter.hutterer at who-t.net>
Reviewed-by: Jeremy Huddleston <jeremyhu at apple.com>
---
Changes to v1:
- adjustments for SysCounterGetPrivate instead of previous macro

 Xext/sync.c |   47 ++++++++++++++++++++++++++++-------------------
 1 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/Xext/sync.c b/Xext/sync.c
index 050a96e..4c63f64 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -2711,9 +2711,10 @@ SyncInitServerTime(void)
  * IDLETIME implementation
  */
 
-static SyncCounter *IdleTimeCounter;
-static XSyncValue *pIdleTimeValueLess;
-static XSyncValue *pIdleTimeValueGreater;
+typedef struct {
+    XSyncValue *value_less;
+    XSyncValue *value_greater;
+} IdleCounterPriv;
 
 static void
 IdleTimeQueryValue (pointer pCounter, CARD64 *pValue_return)
@@ -2725,9 +2726,10 @@ IdleTimeQueryValue (pointer pCounter, CARD64 *pValue_return)
 static void
 IdleTimeBlockHandler(pointer pCounter, struct timeval **wt, pointer LastSelectMask)
 {
-    SyncCounter *counter = IdleTimeCounter;
-    XSyncValue *less = pIdleTimeValueLess,
-	       *greater = pIdleTimeValueGreater;
+    SyncCounter *counter = pCounter;
+    IdleCounterPriv *priv = SysCounterGetPrivate(counter);
+    XSyncValue *less = priv->value_less,
+	       *greater = priv->value_greater;
     XSyncValue idle, old_idle;
     SyncTriggerList *list = counter->sync.pTriglist;
     SyncTrigger *trig;
@@ -2801,10 +2803,11 @@ IdleTimeBlockHandler(pointer pCounter, struct timeval **wt, pointer LastSelectMa
 static void
 IdleTimeWakeupHandler (pointer pCounter, int rc, pointer LastSelectMask)
 {
-    SyncCounter *counter = IdleTimeCounter;
+    SyncCounter *counter = pCounter;
+    IdleCounterPriv *priv = SysCounterGetPrivate(counter);
+    XSyncValue *less = priv->value_less,
+	       *greater = priv->value_greater;
     XSyncValue idle;
-    XSyncValue *less = pIdleTimeValueLess,
-	       *greater = pIdleTimeValueGreater;
 
     if (!less && !greater)
 	return;
@@ -2814,7 +2817,7 @@ IdleTimeWakeupHandler (pointer pCounter, int rc, pointer LastSelectMask)
     if ((greater && XSyncValueGreaterOrEqual (idle, *greater)) ||
         (less && XSyncValueLessOrEqual (idle, *less)))
     {
-	SyncChangeCounter (counter, idle);
+	SyncChangeCounter ((SyncCounter*)pCounter, idle);
     }
 }
 
@@ -2822,8 +2825,10 @@ static void
 IdleTimeBracketValues (pointer pCounter, CARD64 *pbracket_less,
                        CARD64 *pbracket_greater)
 {
-    XSyncValue *less = pIdleTimeValueLess,
-	       *greater = pIdleTimeValueGreater;
+    SyncCounter *counter = pCounter;
+    IdleCounterPriv *priv = SysCounterGetPrivate(counter);
+    XSyncValue *less = priv->value_less,
+	       *greater = priv->value_greater;
     Bool registered = (less || greater);
 
     if (registered && !pbracket_less && !pbracket_greater)
@@ -2839,8 +2844,8 @@ IdleTimeBracketValues (pointer pCounter, CARD64 *pbracket_less,
 	                               pCounter);
     }
 
-    pIdleTimeValueGreater = pbracket_greater;
-    pIdleTimeValueLess    = pbracket_less;
+    priv->value_greater = pbracket_greater;
+    priv->value_less    = pbracket_less;
 }
 
 static void
@@ -2848,14 +2853,18 @@ SyncInitIdleTime (void)
 {
     CARD64 resolution;
     XSyncValue idle;
+    IdleCounterPriv *priv = malloc(sizeof(IdleCounterPriv));
+    SyncCounter *idle_time_counter;
 
     IdleTimeQueryValue (NULL, &idle);
     XSyncIntToValue (&resolution, 4);
 
-    IdleTimeCounter = SyncCreateSystemCounter ("IDLETIME", idle, resolution,
-                                               XSyncCounterUnrestricted,
-                                               IdleTimeQueryValue,
-                                               IdleTimeBracketValues);
+    idle_time_counter = SyncCreateSystemCounter("IDLETIME", idle, resolution,
+						XSyncCounterUnrestricted,
+						IdleTimeQueryValue,
+						IdleTimeBracketValues);
 
-    pIdleTimeValueLess = pIdleTimeValueGreater = NULL;
+    priv->value_less = priv->value_greater = NULL;
+
+    idle_time_counter->pSysCounterInfo->private = priv;
 }
-- 
1.7.7.6



More information about the xorg-devel mailing list