FreeBSD Bugzilla – Attachment 113782 Details for
Bug 155374
[patch] grdc(6) timing loop still broken
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
file.diff
file.diff (text/plain), 1.96 KB, created by
Andy Farkas
on 2011-03-08 12:40:09 UTC
(
hide
)
Description:
file.diff
Filename:
MIME Type:
Creator:
Andy Farkas
Created:
2011-03-08 12:40:09 UTC
Size:
1.96 KB
patch
obsolete
>--- /usr/src/games/grdc/grdc.c 2010-08-28 13:04:04.000000000 +1000 >+++ ./grdc.c 2011-03-08 22:04:00.000000000 +1000 >@@ -26,7 +26,12 @@ > #define XLENGTH 58 > #define YDEPTH 7 > >-struct timespec now; >+/* now: current time we start the loop >+ delay: current time we finish displaying the time >+ wait: amount of time we wait until next now second >+ scrold: amount of time between scrolling >+*/ >+struct timespec delay, now, wait, scrold; > struct tm *tm; > > short disp[11] = { >@@ -54,8 +59,6 @@ > int > main(int argc, char *argv[]) > { >- struct timespec delay; >- time_t prev_sec; > long t, a; > int i, j, s, k; > int n; >@@ -69,6 +72,7 @@ > switch (ch) { > case 's': > scrol = 1; >+ scrold.tv_nsec = 40000000; > break; > case 't': > t12 = 1; >@@ -138,9 +142,9 @@ > > attrset(COLOR_PAIR(2)); > } >- clock_gettime(CLOCK_REALTIME_FAST, &now); >- prev_sec = now.tv_sec; >+ > do { >+ clock_gettime(CLOCK_REALTIME_FAST, &now); > mask = 0; > tm = localtime(&now.tv_sec); > set(tm->tm_sec%10, 0); >@@ -191,25 +195,31 @@ > } > if(!s) { > refresh(); >+ nanosleep(&scrold, NULL); > } > } > } > movto(6, 0); > refresh(); >- clock_gettime(CLOCK_REALTIME_FAST, &now); >- if (now.tv_sec == prev_sec) { >- if (delay.tv_nsec > 0) { >- delay.tv_sec = 0; >- delay.tv_nsec = 1000000000 - now.tv_nsec; >- } else { >- delay.tv_sec = 1; >- delay.tv_nsec = 0; >+ >+ clock_gettime(CLOCK_REALTIME_FAST, &delay); >+ >+ if (delay.tv_sec == now.tv_sec) { >+ wait.tv_nsec = 1000000000 - (delay.tv_nsec - now.tv_nsec); >+ --n; >+ } >+ else { >+ if (delay.tv_nsec < now.tv_nsec) { >+ wait.tv_nsec = now.tv_nsec - delay.tv_nsec; >+ n -= delay.tv_sec - now.tv_sec; >+ } >+ else { >+ wait.tv_nsec = (1000000000 - delay.tv_nsec) + now.tv_nsec; >+ n -= (delay.tv_sec - now.tv_sec) + 1; > } >- nanosleep(&delay, NULL); >- clock_gettime(CLOCK_REALTIME_FAST, &now); > } >- n -= now.tv_sec - prev_sec; >- prev_sec = now.tv_sec; >+ nanosleep(&wait, NULL); >+ > if (sigtermed) { > standend(); > clear();
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 155374
: 113782