summaryrefslogtreecommitdiffstats
path: root/src/sandglass.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-09-17 13:33:10 +0000
committerTavian Barnes <tavianator@gmail.com>2009-09-17 13:33:10 +0000
commit500a64194f6dd1d226e0ae94873dc435284d6727 (patch)
tree275e8ddcd4abe73b19e77177f2fe69fc09f00887 /src/sandglass.c
parent9a358c3cdf8eb34754cc5544e2a5e0f67c022f8d (diff)
downloadlibsandglass-500a64194f6dd1d226e0ae94873dc435284d6727.tar.xz
Generalise handling of negative grain differences.
Diffstat (limited to 'src/sandglass.c')
-rw-r--r--src/sandglass.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/sandglass.c b/src/sandglass.c
index 3399b73..c63e2a0 100644
--- a/src/sandglass.c
+++ b/src/sandglass.c
@@ -186,7 +186,7 @@ sandglass_elapse(sandglass_t *sandglass)
sandglass->grains -= oldgrains;
/* Magical correction for timespec-based grains */
if (sandglass->grains < 0)
- sandglass->grains += 2000000000L;
+ sandglass->grains += sandglass->adjustment;
sandglass->grains /= sandglass->loops;
return 0;
@@ -226,7 +226,8 @@ sandglass_real_gettime(sandglass_t *sandglass)
if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
return -1;
}
- sandglass->grains = sandglass_timespec_grains(&ts);
+ sandglass->grains = sandglass_timespec_grains(&ts);
+ sandglass->adjustment = 2000000000L;
break;
default:
@@ -249,7 +250,8 @@ sandglass_real_gettime(sandglass_t *sandglass)
return -1;
} else
return -1;
- sandglass->grains = sandglass_timespec_grains(&ts);
+ sandglass->grains = sandglass_timespec_grains(&ts);
+ sandglass->adjustment = 2000000000L;
break;
case SANDGLASS_SYSTEM: