Supports GNU, FreeBSD, OSX, and Alpine.
Signed-off-by: John Coyle <dx9err@gmail.com>
CHECK_FUNCTION_EXISTS(pipe2 HAVE_PIPE2)
set(CMAKE_REQUIRED_LIBRARIES pthread)
CHECK_FUNCTION_EXISTS(pthread_spin_init HAVE_PTHREAD_SPINLOCK)
+CHECK_FUNCTION_EXISTS(pthread_set_name_np HAVE_PTHREAD_SET_NAME_NP)
+CHECK_FUNCTION_EXISTS(pthread_setname_np HAVE_PTHREAD_SETNAME_NP)
+CHECK_FUNCTION_EXISTS(pthread_getname_np HAVE_PTHREAD_GETNAME_NP)
CHECK_FUNCTION_EXISTS(eventfd HAVE_EVENTFD)
CHECK_INCLUDE_FILE_CXX("boost/asio/coroutine.hpp" HAVE_BOOST_ASIO_COROUTINE)
CFLAGS="$PTHREAD_CFLAGS $CFLAGS"
AC_CHECK_FUNC([pthread_spin_init],
[AC_DEFINE(HAVE_PTHREAD_SPINLOCK, 1, [Define if you have pthread_spin_init])])
+AC_CHECK_FUNCS([pthread_getname_np pthread_setname_np pthread_set_name_np])
LIBS="$saved_LIBS"
CFLAGS="$saved_CFLAGS"
*
*/
+#include "include/compat.h"
+
#include <iostream>
#include <sstream>
using namespace std;
*
*/
+#include "include/compat.h"
+
#include <sstream>
#include "include/types.h"
std::stringstream ss;
char name[16] = {0};
-#if !defined(__FreeBSD__)
pthread_getname_np(pthread_self(), name, sizeof(name));
-#endif
ss << name << " thread " << name;
heartbeat_handle_d *hb = cct->get_heartbeat_map()->add_worker(ss.str(), pthread_self());
std::stringstream ss;
char name[16] = {0};
-#if !defined(__FreeBSD__)
pthread_getname_np(pthread_self(), name, sizeof(name));
-#endif
ss << name << " thread " << name;
heartbeat_handle_d *hb = cct->get_heartbeat_map()->add_worker(ss.str(), pthread_self());
*
*/
+#include "include/compat.h"
+
#include "common/BackTrace.h"
#include "common/debug.h"
#include "global/pidfile.h"
// presumably dump core-- will handle it.
char buf[1024];
char pthread_name[16] = {0}; //limited by 16B include terminating null byte.
-#if !defined(__FreeBSD__)
int r = pthread_getname_np(pthread_self(), pthread_name, sizeof(pthread_name));
(void)r;
-#endif
#if defined(__sun)
char message[SIG2STR_MAX];
sig2str(signum,message);
#ifndef CEPH_COMPAT_H
#define CEPH_COMPAT_H
+#include "acconfig.h"
+
#if defined(__FreeBSD__)
/* Make sure that ENODATA is defined in the correct way */
#endif
#endif
-/* Fix a small name diff */
-#define pthread_setname_np pthread_set_name_np
/* And include the extra required include file */
#include <pthread_np.h>
#define MSG_DONTWAIT MSG_NONBLOCK
#endif
+#if defined(HAVE_PTHREAD_SETNAME_NP)
+ #if defined(__APPLE__)
+ #define pthread_setname_np(thread, name) ({ \
+ int __result = 0; \
+ if (thread == pthread_self()) \
+ __result = pthread_setname_np(name) \
+ __result; })
+ #endif
+#elif defined(HAVE_PTHREAD_SET_NAME_NP)
+ /* Fix a small name diff */
+ #define pthread_setname_np pthread_set_name_np
+#else
+ /* compiler warning free success noop */
+ #define pthread_setname_np(thread, name) ({ \
+ int __i = 0; \
+ __i; })
+#endif
+
+#if !defined(HAVE_PTHREAD_GETNAME_NP)
+ /* compiler warning free success noop */
+ #define pthread_getname_np(thread, name, len) ({ \
+ if (name != NULL) \
+ *name = '\0'; \
+ 0; })
+#endif
+
#endif /* !CEPH_COMPAT_H */
/* Version number of package */
#cmakedefine VERSION "@VERSION@"
+/* Defined if pthread_setname_np() is available */
+#cmakedefine HAVE_PTHREAD_SETNAME_NP 1
+
+/* Defined if pthread_set_name_np() is available */
+#cmakedefine HAVE_PTHREAD_SET_NAME_NP
+
+/* Defined if pthread_getname_np() is available */
+#cmakedefine HAVE_PTHREAD_GETNAME_NP 1
+
#endif /* CONFIG_H */