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

Peter Hutterer peter.hutterer at who-t.net
Tue Mar 13 22:47:23 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>
---
 Xext/sync.c |   45 ++++++++++++++++++++++++++-------------------
 1 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/Xext/sync.c b/Xext/sync.c
index 17e64e5..df0aa0d 100644
--- a/Xext/sync.c
+++ b/Xext/sync.c
@@ -2732,9 +2732,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)
@@ -2746,9 +2747,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;
+    IdleCounterPriv *priv = SYSCOUNTERPRIV(pCounter);
+    SyncCounter *counter = pCounter;
+    XSyncValue *less = priv->value_less,
+	       *greater = priv->value_greater;
     XSyncValue idle, old_idle;
     SyncTriggerList *list = counter->sync.pTriglist;
     SyncTrigger *trig;
@@ -2822,10 +2824,10 @@ IdleTimeBlockHandler(pointer pCounter, struct timeval **wt, pointer LastSelectMa
 static void
 IdleTimeWakeupHandler (pointer pCounter, int rc, pointer LastSelectMask)
 {
-    SyncCounter *counter = IdleTimeCounter;
+    IdleCounterPriv *priv = SYSCOUNTERPRIV(pCounter);
+    XSyncValue *less = priv->value_less,
+	       *greater = priv->value_greater;
     XSyncValue idle;
-    XSyncValue *less = pIdleTimeValueLess,
-	       *greater = pIdleTimeValueGreater;
 
     if (!less && !greater)
 	return;
@@ -2835,7 +2837,7 @@ IdleTimeWakeupHandler (pointer pCounter, int rc, pointer LastSelectMask)
     if ((greater && XSyncValueGreaterOrEqual (idle, *greater)) ||
         (less && XSyncValueLessOrEqual (idle, *less)))
     {
-	SyncChangeCounter (counter, idle);
+	SyncChangeCounter ((SyncCounter*)pCounter, idle);
     }
 }
 
@@ -2843,8 +2845,9 @@ static void
 IdleTimeBracketValues (pointer pCounter, CARD64 *pbracket_less,
                        CARD64 *pbracket_greater)
 {
-    XSyncValue *less = pIdleTimeValueLess,
-	       *greater = pIdleTimeValueGreater;
+    IdleCounterPriv *priv = SYSCOUNTERPRIV(pCounter);
+    XSyncValue *less = priv->value_less,
+	       *greater = priv->value_greater;
     Bool registered = (less || greater);
 
     if (registered && !pbracket_less && !pbracket_greater)
@@ -2860,8 +2863,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
@@ -2869,14 +2872,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;
+
+    SYSCOUNTERPRIV(idle_time_counter) = priv;
 }
-- 
1.7.7.6



More information about the xorg-devel mailing list