diff options
author | Jon Lund Steffensen <jonlst@gmail.com> | 2014-12-28 13:13:21 -0500 |
---|---|---|
committer | Jon Lund Steffensen <jonlst@gmail.com> | 2014-12-28 13:13:21 -0500 |
commit | ba422bd78ec0d78611d0bced54c98d80da20a18d (patch) | |
tree | af86a219f177b1d45a2bcd58cceb87b8889e869a /src | |
parent | systemtime: Fix includes and check for _POSIX_TIMERS (diff) | |
download | redshift-ng-ba422bd78ec0d78611d0bced54c98d80da20a18d.tar.gz redshift-ng-ba422bd78ec0d78611d0bced54c98d80da20a18d.tar.bz2 redshift-ng-ba422bd78ec0d78611d0bced54c98d80da20a18d.tar.xz |
systemtime: Add function wrapping platform sleep function
Adds systemtime_msleep() which sleeps for a number of milliseconds.
This wraps Sleep() on windows and usleep() on other platforms.
Diffstat (limited to 'src')
-rw-r--r-- | src/redshift.c | 13 | ||||
-rw-r--r-- | src/systemtime.c | 11 | ||||
-rw-r--r-- | src/systemtime.h | 1 |
3 files changed, 17 insertions, 8 deletions
diff --git a/src/redshift.c b/src/redshift.c index b09f39c..5f7d22b 100644 --- a/src/redshift.c +++ b/src/redshift.c @@ -25,7 +25,6 @@ #include <stdlib.h> #include <unistd.h> #include <string.h> -#include <time.h> #include <math.h> #include <locale.h> #include <errno.h> @@ -1583,13 +1582,11 @@ main(int argc, char *argv[]) sizeof(color_setting_t)); /* Sleep for 5 seconds or 0.1 second. */ -#ifndef _WIN32 - if (short_trans_delta) usleep(SLEEP_DURATION_SHORT*1000); - else usleep(SLEEP_DURATION*1000); -#else /* ! _WIN32 */ - if (short_trans_delta) Sleep(SLEEP_DURATION_SHORT); - else Sleep(SLEEP_DURATION); -#endif /* ! _WIN32 */ + if (short_trans_delta) { + systemtime_msleep(SLEEP_DURATION_SHORT); + } else { + systemtime_msleep(SLEEP_DURATION); + } } /* Restore saved gamma ramps */ diff --git a/src/systemtime.c b/src/systemtime.c index 84106c5..0d0cb85 100644 --- a/src/systemtime.c +++ b/src/systemtime.c @@ -68,3 +68,14 @@ systemtime_get_time(double *t) return 0; } + +/* Sleep for a number of milliseconds. */ +void +systemtime_msleep(unsigned int msecs) +{ +#ifndef _WIN32 + usleep(msecs*1000); +#else + Sleep(msecs); +#endif +} diff --git a/src/systemtime.h b/src/systemtime.h index 0a6a66c..184e41d 100644 --- a/src/systemtime.h +++ b/src/systemtime.h @@ -22,5 +22,6 @@ int systemtime_get_time(double *now); +void systemtime_msleep(unsigned int msecs); #endif /* ! REDSHIFT_SYSTEMTIME_H */ |