summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hornsey <fred@hornsey.us>2019-04-11 23:43:06 -0500
committerFred Hornsey <fred@hornsey.us>2019-04-11 23:43:06 -0500
commite06e966e10b4edb27f9813ddffc34529abd4bb91 (patch)
tree4de96a9c581cd10fe80439df5448f49fe98b645a
parent6077b11bb47d50d264f1ed095df2a0c499f74c90 (diff)
downloadATCD-e06e966e10b4edb27f9813ddffc34529abd4bb91.tar.gz
Add ACE_OS::thr_gettid()
-rw-r--r--ACE/ace/OS_NS_Thread.cpp13
-rw-r--r--ACE/ace/OS_NS_Thread.h18
-rw-r--r--ACE/ace/OS_NS_Thread.inl11
-rw-r--r--ACE/ace/config-linux.h4
4 files changed, 45 insertions, 1 deletions
diff --git a/ACE/ace/OS_NS_Thread.cpp b/ACE/ace/OS_NS_Thread.cpp
index 8a052271775..315713a35a4 100644
--- a/ACE/ace/OS_NS_Thread.cpp
+++ b/ACE/ace/OS_NS_Thread.cpp
@@ -17,6 +17,7 @@
#include "ace/Thread_Mutex.h"
#include "ace/Condition_Thread_Mutex.h"
#include "ace/Guard_T.h"
+#include "ace/OS_NS_sys_resource.h"
extern "C" void
ACE_MUTEX_LOCK_CLEANUP_ADAPTER_NAME (void *args)
@@ -4806,6 +4807,18 @@ ACE_OS::unique_name (const void *object,
}
#endif
+#ifdef ACE_HAS_GETTID
+pid_t
+ACE_OS::thr_gettid ()
+{
+# ifdef ACE_LINUX
+ return syscall (SYS_gettid);
+# else
+# error "No implementation for thr_gettid(), please disable ACE_HAS_GETTID"
+# endif
+}
+#endif
+
ACE_END_VERSIONED_NAMESPACE_DECL
#if defined (ACE_VXWORKS) && !defined (__RTP__)
diff --git a/ACE/ace/OS_NS_Thread.h b/ACE/ace/OS_NS_Thread.h
index f932a701cea..061351c2dcd 100644
--- a/ACE/ace/OS_NS_Thread.h
+++ b/ACE/ace/OS_NS_Thread.h
@@ -1754,6 +1754,24 @@ namespace ACE_OS {
ACE_NAMESPACE_INLINE_FUNCTION
ssize_t thr_id (char buffer[], size_t buffer_length);
+#ifdef ACE_HAS_GETTID
+ /**
+ * Wrapper for pid_t gettid(). For systems that support it (only Linux as of
+ * writing), get the system-wide thread id (TID) for the current thread.
+ *
+ * These are similar to PIDs and, on x86 Linux at least, are much shorter
+ * than the what is returned from thr_id(), which is represents a address.
+ */
+ pid_t thr_gettid ();
+
+ /**
+ * Puts the string representation of pid_t thr_gettid() into the buffer and
+ * returns number of bytes added.
+ */
+ ACE_NAMESPACE_INLINE_FUNCTION
+ ssize_t thr_gettid (char buffer[], size_t buffer_length);
+#endif
+
/// State is THR_CANCEL_ENABLE or THR_CANCEL_DISABLE
ACE_NAMESPACE_INLINE_FUNCTION
int thr_setcancelstate (int new_state, int *old_state);
diff --git a/ACE/ace/OS_NS_Thread.inl b/ACE/ace/OS_NS_Thread.inl
index d4023d05704..53866dde742 100644
--- a/ACE/ace/OS_NS_Thread.inl
+++ b/ACE/ace/OS_NS_Thread.inl
@@ -3178,12 +3178,21 @@ ACE_OS::thr_id (char buffer[], size_t buffer_length)
#else /* ACE_HAS_OPAQUE_PTHREAD_T */
return ACE_OS::snprintf (buffer,
buffer_length,
- "%lu",
+ "%lx",
(unsigned long) t_id);
#endif /* ACE_HAS_OPAQUE_PTHREAD_T */
#endif /* WIN32 */
}
+#ifdef ACE_HAS_GETTID
+ACE_INLINE ssize_t
+ACE_OS::thr_gettid (char buffer[], size_t buffer_length)
+{
+ return ACE_OS::snprintf (buffer, buffer_length, "%u",
+ static_cast<unsigned> (ACE_OS::thr_gettid()));
+}
+#endif
+
ACE_INLINE ACE_thread_t
ACE_OS::thr_self (void)
{
diff --git a/ACE/ace/config-linux.h b/ACE/ace/config-linux.h
index e248aea30b3..cb11f84ae63 100644
--- a/ACE/ace/config-linux.h
+++ b/ACE/ace/config-linux.h
@@ -449,6 +449,10 @@
#endif /* __UCLIBC__ */
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION (2,4,11))
+# define ACE_HAS_GETTID // See ACE_OS::thr_gettid()
+#endif
+
#include /**/ "ace/post.h"
#endif /* ACE_CONFIG_LINUX_H */