grdc(6): de-obfuscate the timekeeping of now/delay
- 'now' only contains current time readings - delay is only used as parameter to nanosleep - prev_sec contains the time_t of the previous loop iteration Submitted by: bde MFC after: 2 weeks
This commit is contained in:
parent
227405d48c
commit
ec2368eb92
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=210827
@ -55,6 +55,7 @@ int
|
|||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct timespec delay;
|
struct timespec delay;
|
||||||
|
time_t prev_sec;
|
||||||
long t, a;
|
long t, a;
|
||||||
int i, j, s, k;
|
int i, j, s, k;
|
||||||
int n;
|
int n;
|
||||||
@ -138,6 +139,7 @@ main(int argc, char *argv[])
|
|||||||
attrset(COLOR_PAIR(2));
|
attrset(COLOR_PAIR(2));
|
||||||
}
|
}
|
||||||
clock_gettime(CLOCK_REALTIME_FAST, &now);
|
clock_gettime(CLOCK_REALTIME_FAST, &now);
|
||||||
|
prev_sec = now.tv_sec;
|
||||||
do {
|
do {
|
||||||
mask = 0;
|
mask = 0;
|
||||||
tm = localtime(&now.tv_sec);
|
tm = localtime(&now.tv_sec);
|
||||||
@ -194,20 +196,20 @@ main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
movto(6, 0);
|
movto(6, 0);
|
||||||
refresh();
|
refresh();
|
||||||
clock_gettime(CLOCK_REALTIME_FAST, &delay);
|
clock_gettime(CLOCK_REALTIME_FAST, &now);
|
||||||
if (delay.tv_sec == now.tv_sec) {
|
if (now.tv_sec == prev_sec) {
|
||||||
if (delay.tv_nsec > 0) {
|
if (delay.tv_nsec > 0) {
|
||||||
delay.tv_sec = 0;
|
delay.tv_sec = 0;
|
||||||
delay.tv_nsec = 1000000000 - delay.tv_nsec;
|
delay.tv_nsec = 1000000000 - now.tv_nsec;
|
||||||
} else {
|
} else {
|
||||||
delay.tv_sec = 1;
|
delay.tv_sec = 1;
|
||||||
delay.tv_nsec = 0;
|
delay.tv_nsec = 0;
|
||||||
}
|
}
|
||||||
nanosleep(&delay, NULL);
|
nanosleep(&delay, NULL);
|
||||||
clock_gettime(CLOCK_REALTIME_FAST, &delay);
|
clock_gettime(CLOCK_REALTIME_FAST, &now);
|
||||||
}
|
}
|
||||||
n -= delay.tv_sec - now.tv_sec;
|
n -= now.tv_sec - prev_sec;
|
||||||
now.tv_sec = delay.tv_sec;
|
prev_sec = now.tv_sec;
|
||||||
if (sigtermed) {
|
if (sigtermed) {
|
||||||
standend();
|
standend();
|
||||||
clear();
|
clear();
|
||||||
|
Loading…
Reference in New Issue
Block a user