diff options
author | Constantin Kaplinsky <const@tightvnc.com> | 2006-02-16 13:01:22 +0000 |
---|---|---|
committer | Constantin Kaplinsky <const@tightvnc.com> | 2006-02-16 13:01:22 +0000 |
commit | 2f12537c5fabfb231515f75e7cf2114d7b2e6010 (patch) | |
tree | 185326be6e13b2ca339e43427e253d6a5bc069a9 /x0vncserver | |
parent | 3f56fa75f717616d972eb132d461ca12d33d7d0a (diff) | |
download | tigervnc-2f12537c5fabfb231515f75e7cf2114d7b2e6010.tar.gz tigervnc-2f12537c5fabfb231515f75e7cf2114d7b2e6010.zip |
Corrected algorithm of adjusting polling intervals, to make sudden
changes more graceful.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@491 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'x0vncserver')
-rw-r--r-- | x0vncserver/x0vncserver.cxx | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/x0vncserver/x0vncserver.cxx b/x0vncserver/x0vncserver.cxx index 7b8c6609..af63ad00 100644 --- a/x0vncserver/x0vncserver.cxx +++ b/x0vncserver/x0vncserver.cxx @@ -332,19 +332,37 @@ static void adjustPollingCycle(int *cycle, CPUMonitor *mon) { int coeff = mon->check(); if (coeff < 90 || coeff > 110) { -#ifdef DEBUG - int oldPollingCycle = *cycle; -#endif - *cycle = (*cycle * 100 + coeff/2) / coeff; - if (*cycle < (int)pollingCycle) { - *cycle = (int)pollingCycle; - } else if (*cycle > (int)pollingCycle * 32) { - *cycle = (int)pollingCycle * 32; + int oldValue = *cycle; + int newValue = (oldValue * 100 + coeff/2) / coeff; + + // Correct sudden changes. + if (newValue < oldValue / 2) { + newValue = oldValue / 2; + } else if (newValue > oldValue * 2) { + newValue = oldValue * 2; + } + + // Compute upper limit. + int upperLimit = (int)pollingCycle * 32; + if (upperLimit < 100) { + upperLimit = 100; + } else if (upperLimit > 1000) { + upperLimit = 1000; } + + // Limit lower and upper bounds. + if (newValue < (int)pollingCycle) { + newValue = (int)pollingCycle; + } else if (newValue > upperLimit) { + newValue = upperLimit; + } + + if (newValue != oldValue) { + *cycle = newValue; #ifdef DEBUG - if (*cycle != oldPollingCycle) - fprintf(stderr, "\t[new cycle %dms]\n", *cycle); + fprintf(stderr, "\t[new cycle %dms]\n", newValue); #endif + } } } |