summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAliaksey Kandratsenka <alk@tut.by>2014-01-04 18:28:36 -0800
committerAliaksey Kandratsenka <alk@tut.by>2014-01-04 18:28:36 -0800
commit4c274b9e20132230e62117ff583ebadd83081d90 (patch)
treef1a7c7c269a465761f60819814fdb49110baaf6e
parent1458ee2239e0791567e69112931dc17eb0456cf8 (diff)
downloadgperftools-4c274b9e20132230e62117ff583ebadd83081d90.tar.gz
issue-592: handle recent mingw with C++11 threads
Somehow it's c++ headers (like string) define pthread symbols without even us asking for. That breaks old assumption that pthread symbols are not available on windows. In order to fix that we detect this condition in configure.ac and avoid defining windows versions of pthread symbols.
-rwxr-xr-xMakefile.am4
-rw-r--r--configure.ac20
-rw-r--r--src/windows/mingw.h2
-rw-r--r--src/windows/port.h20
4 files changed, 35 insertions, 11 deletions
diff --git a/Makefile.am b/Makefile.am
index b0a9dfb..caa19a7 100755
--- a/Makefile.am
+++ b/Makefile.am
@@ -264,7 +264,11 @@ libsysinfo_la_LIBADD += -lshlwapi
# patch_functions.cc #includes tcmalloc.cc, so no need to link it in.
TCMALLOC_CC =
# windows has its own system for threads and system memory allocation.
+if HAVE_PTHREAD_DESPITE_ASKING_FOR
+MAYBE_THREADS_CC = src/maybe_threads.cc
+else
MAYBE_THREADS_CC =
+endif
SYSTEM_ALLOC_CC =
else !MINGW
# spinlock is the only code that uses atomicops.
diff --git a/configure.ac b/configure.ac
index 1fb8abd..f76c060 100644
--- a/configure.ac
+++ b/configure.ac
@@ -348,6 +348,26 @@ AC_CHECK_DECLS(uname,,, [#include <sys/utsname.h>])
# In fact, a lot of the code in this directory depends on pthreads
ACX_PTHREAD
+AC_LANG_SAVE
+AC_LANG_CPLUSPLUS
+AC_MSG_CHECKING([whether pthread symbols are available in C++ without including pthread.h])
+acx_pthread_despite_asking_for=no
+AC_LINK_IFELSE(
+ [AC_LANG_PROGRAM([
+ #include <string>
+ #include <vector>
+ ],[
+ pthread_t th; pthread_join(th, 0);
+ ])],[
+ acx_pthread_despite_asking_for=yes
+ AC_DEFINE(HAVE_PTHREAD_DESPITE_ASKING_FOR, 1, [defined to 1 if pthread symbols are exposed even without include pthread.h])
+ AC_DEFINE(HAVE_PTHREAD, 1, [])
+ ])
+AC_MSG_RESULT([$acx_pthread_despite_asking_for])
+AC_LANG_RESTORE
+
+AM_CONDITIONAL(HAVE_PTHREAD_DESPITE_ASKING_FOR, test x"$acx_pthread_despite_asking_for" == xyes)
+
# Find out what namespace 'normal' STL code lives in
AC_CXX_STL_NAMESPACE
diff --git a/src/windows/mingw.h b/src/windows/mingw.h
index 5acefeb..0586e62 100644
--- a/src/windows/mingw.h
+++ b/src/windows/mingw.h
@@ -59,7 +59,9 @@
// Some mingw distributions have a pthreads wrapper, but it doesn't
// work as well as native windows spinlocks (at least for us). So
// pretend the pthreads wrapper doesn't exist, even when it does.
+#ifndef HAVE_PTHREAD_DESPITE_ASKING_FOR
#undef HAVE_PTHREAD
+#endif
#define HAVE_PID_T
diff --git a/src/windows/port.h b/src/windows/port.h
index 0a9b0d8..c66a296 100644
--- a/src/windows/port.h
+++ b/src/windows/port.h
@@ -133,7 +133,14 @@ inline bool pthread_equal(pthread_t left, pthread_t right) {
return left == right;
}
+/*
+ * windows/port.h defines compatibility APIs for several .h files, which
+ * we therefore shouldn't be #including directly. This hack keeps us from
+ * doing so. TODO(csilvers): do something more principled.
+ */
+#define GOOGLE_MAYBE_THREADS_H_ 1
/* This replaces maybe_threads.{h,cc} */
+
EXTERN_C pthread_key_t PthreadKeyCreate(void (*destr_fn)(void*)); /* port.cc */
inline int perftools_pthread_key_create(pthread_key_t *pkey,
@@ -165,12 +172,13 @@ EXTERN_C int perftools_pthread_once(pthread_once_t *once_control,
void (*init_routine)(void));
#endif /* __cplusplus */
-#endif /* HAVE_PTHREAD */
inline void sched_yield(void) {
Sleep(0);
}
+#endif /* HAVE_PTHREAD */
+
/*
* __declspec(thread) isn't usable in a dll opened via LoadLibrary().
* But it doesn't work to LoadLibrary() us anyway, because of all the
@@ -474,16 +482,6 @@ inline long long atoll(const char *nptr) {
/* tcmalloc.cc calls this so we can patch VirtualAlloc() et al. */
extern void PatchWindowsFunctions();
-// ----------------------------------- BUILD-SPECIFIC
-
-/*
- * windows/port.h defines compatibility APIs for several .h files, which
- * we therefore shouldn't be #including directly. This hack keeps us from
- * doing so. TODO(csilvers): do something more principled.
- */
-#define GOOGLE_MAYBE_THREADS_H_ 1
-
-
#endif /* _WIN32 */
#undef inline