Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in some cases usleep doesn't accept more than 1.000.000 microseconds #174

Closed
aniou opened this issue Feb 8, 2015 · 0 comments
Closed

in some cases usleep doesn't accept more than 1.000.000 microseconds #174

aniou opened this issue Feb 8, 2015 · 0 comments
Labels

Comments

@aniou
Copy link

aniou commented Feb 8, 2015

When SLEEP_DURATION is defined as 5000 in redshift.c and we call usleep(3) with 1000 multiplier in systemtime.c in systemtime_msleep() then, at least in NetBSD, usleep(3) doesn't work at all due to limit to 1.000.000 microseconds in this call. This leads to high CPU load due to lack of efficient sleep in redshift loop.

Converting to nanosleep(2) fixes this issue, small patch below (more like illustration rather than real solution but I tried to create a drop-in replacement).

--- systemtime.c.orig   2015-02-08 11:10:56.000000000 +0100
+++ systemtime.c        2015-02-08 11:32:16.000000000 +0100
@@ -74,7 +74,16 @@
 systemtime_msleep(unsigned int msecs)
 {
 #ifndef _WIN32
-       usleep(msecs*1000);
+        struct timespec wait;
+
+        if (msecs >= 1000) {
+            wait.tv_sec = (time_t)(msecs / 1000);
+            wait.tv_nsec = 0;
+        } else {
+            wait.tv_sec = 0;
+            wait.tv_nsec = msecs*1000*1000;
+        }
+        nanosleep(&wait, NULL);
 #else
        Sleep(msecs);
 #endif
@jonls jonls added bug and removed bug labels Feb 9, 2015
@jonls jonls closed this as completed in 8b0a67a Feb 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants