From d8e12e94ea09eaf8b040c6887f75cdf832b5619b Mon Sep 17 00:00:00 2001 From: "alkondratenko@gmail.com" Date: Sat, 20 Jul 2013 21:35:14 +0000 Subject: issue-549: handle most recent mingw that has sleep and nanosleep I.e. we have to check their presence in configure and in case of their presence we have to avoid re-defining then in window's port.h git-svn-id: http://gperftools.googlecode.com/svn/trunk@223 6b5cf1ce-ec42-a296-1ba9-69fdba395a50 --- configure.ac | 9 +++++++++ src/windows/port.h | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/configure.ac b/configure.ac index 033f224..06da531 100644 --- a/configure.ac +++ b/configure.ac @@ -354,6 +354,15 @@ AC_PROGRAM_INVOCATION_NAME # Make the install prefix available, to figure out where to look for pprof AC_INSTALL_PREFIX +dnl only very recent mingw has sleep and nanosleep +case "$host" in + *-mingw*) + AC_CHECK_DECLS([sleep], [], [], [#include ]) + AC_CHECK_DECLS([nanosleep], [], [], [#include ]) + ;; +esac + + # For windows, this has a non-trivial value (__declspec(export)), but any # system that uses configure wants this to be the empty string. AC_DEFINE(PERFTOOLS_DLL_DECL,, diff --git a/src/windows/port.h b/src/windows/port.h index 0da2eee..6c90a8d 100644 --- a/src/windows/port.h +++ b/src/windows/port.h @@ -413,10 +413,17 @@ EXTERN_C int getpagesize(); /* in port.cc */ inline void srandom(unsigned int seed) { srand(seed); } inline long random(void) { return rand(); } + +#ifndef HAVE_DECL_SLEEP +#define HAVE_DECL_SLEEP 0 +#endif + +#if !HAVE_DECL_SLEEP inline unsigned int sleep(unsigned int seconds) { Sleep(seconds * 1000); return 0; } +#endif // mingw64 seems to define timespec (though mingw.org mingw doesn't), // protected by the _TIMESPEC_DEFINED macro. @@ -427,10 +434,17 @@ struct timespec { }; #endif +#ifndef HAVE_DECL_NANOSLEEP +#define HAVE_DECL_NANOSLEEP 0 +#endif + +// latest mingw64 has nanosleep. Earlier mingw and MSVC do not +#if !HAVE_DECL_NANOSLEEP inline int nanosleep(const struct timespec *req, struct timespec *rem) { Sleep(req->tv_sec * 1000 + req->tv_nsec / 1000000); return 0; } +#endif #ifndef __MINGW32__ inline long long int strtoll(const char *nptr, char **endptr, int base) { -- cgit v1.2.1