summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-09-20 16:09:53 +0000
committerTavian Barnes <tavianator@gmail.com>2009-09-20 16:09:53 +0000
commit0b12bb29adc33255b97d2fb995ef145f0127d950 (patch)
tree2e3d09bf8b95419618505522f5b12fe78911c260 /src
parent1a2471411605302574df89cc82d7a3b4da0b2005 (diff)
downloadlibsandglass-0b12bb29adc33255b97d2fb995ef145f0127d950.tar.xz
Make SANDGLASS_REALTICKS accurate to 1 clock cycle.
Diffstat (limited to 'src')
-rw-r--r--src/sandglass.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/sandglass.c b/src/sandglass.c
index c3435d0..b9316e5 100644
--- a/src/sandglass.c
+++ b/src/sandglass.c
@@ -179,15 +179,25 @@ int
sandglass_elapse(sandglass_t *sandglass)
{
long oldgrains = sandglass->grains;
+ sandglass_t baseline;
if (sandglass_real_gettime(sandglass) != 0)
return -1;
sandglass->grains -= oldgrains;
- /* Magical correction for timespec-based grains */
if (sandglass->grains < 0)
+ /* Magical correction for timespec-based grains */
sandglass->grains += sandglass->adjustment;
- sandglass->grains /= sandglass->loops;
+
+ if (sandglass->attributes.resolution == SANDGLASS_REALTICKS) {
+ baseline.attributes.incrementation = SANDGLASS_MONOTONIC;
+ baseline.attributes.resolution = SANDGLASS_CPUTIME;
+ baseline.loops = sandglass->loops;
+
+ sandglass_bench(&baseline, { });
+ sandglass->grains -= baseline.grains;
+ sandglass->grains /= sandglass->loops;
+ }
return 0;
}