summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrad Smith <brad@comstyle.com>2020-08-07 00:00:40 -0400
committerDaniel Black <daniel@mariadb.org>2020-08-28 15:03:43 +1000
commit482cf29e168673f68196a235aff00fc741bf71da (patch)
tree7e4716ec045084f56855a46f6110b8300e584296
parentfe5dbfe723427a3606c41409626dc853f997e679 (diff)
downloadmariadb-git-482cf29e168673f68196a235aff00fc741bf71da.tar.gz
MDEV-23091: perfschema Add support for OpenBSD's getthrid() to retrieve the thread id
-rw-r--r--storage/perfschema/CMakeLists.txt10
-rw-r--r--storage/perfschema/my_thread.h5
-rw-r--r--storage/perfschema/pfs_config.h.cmake1
3 files changed, 16 insertions, 0 deletions
diff --git a/storage/perfschema/CMakeLists.txt b/storage/perfschema/CMakeLists.txt
index c871677d0a9..a40e5ba6206 100644
--- a/storage/perfschema/CMakeLists.txt
+++ b/storage/perfschema/CMakeLists.txt
@@ -298,6 +298,16 @@ int main(int ac, char **av)
}"
HAVE_SYS_GETTID)
+# Check for getthrid()
+CHECK_C_SOURCE_COMPILES("
+#include <unistd.h>
+int main(int ac, char **av)
+{
+ unsigned long long tid = getthrid();
+ return (tid != 0 ? 0 : 1);
+}"
+HAVE_GETTHRID)
+
# Check for pthread_getthreadid_np()
CHECK_C_SOURCE_COMPILES("
#include <pthread_np.h>
diff --git a/storage/perfschema/my_thread.h b/storage/perfschema/my_thread.h
index 12e01a510ed..b9f3f7775ff 100644
--- a/storage/perfschema/my_thread.h
+++ b/storage/perfschema/my_thread.h
@@ -67,6 +67,10 @@ static inline my_thread_os_id_t my_thread_os_id()
/* FreeBSD 10.2 */
return pthread_getthreadid_np();
#else
+#ifdef HAVE_GETTHRID
+ /* OpenBSD */
+ return getthrid();
+#else
#ifdef HAVE_INTEGER_PTHREAD_SELF
/* Unknown platform, fallback. */
return pthread_self();
@@ -74,6 +78,7 @@ static inline my_thread_os_id_t my_thread_os_id()
/* Feature not available. */
return 0;
#endif /* HAVE_INTEGER_PTHREAD_SELF */
+#endif /* HAVE_GETTHRID */
#endif /* HAVE_PTHREAD_GETTHREADID_NP */
#endif /* _WIN32 */
#endif /* HAVE_SYS_GETTID */
diff --git a/storage/perfschema/pfs_config.h.cmake b/storage/perfschema/pfs_config.h.cmake
index 0dc29da72d9..1b518fe3211 100644
--- a/storage/perfschema/pfs_config.h.cmake
+++ b/storage/perfschema/pfs_config.h.cmake
@@ -1,4 +1,5 @@
#cmakedefine HAVE_PTHREAD_THREADID_NP 1
#cmakedefine HAVE_SYS_GETTID 1
+#cmakedefine HAVE_GETTHRID 1
#cmakedefine HAVE_PTHREAD_GETTHREADID_NP 1
#cmakedefine HAVE_INTEGER_PTHREAD_SELF 1