From 0c5f78a223210371576a5c5ec7cda2ae035196bc Mon Sep 17 00:00:00 2001 From: Pete Baker Date: Thu, 19 Mar 2015 13:09:36 -0700 Subject: [PATCH] built and tested - pass --- impl/getcurrentthreadid.cpp | 9 +++++++++ impl/getcurrentthreadid.h | 10 ++++++++++ tests/test-getcurrentthreadid.cpp | 16 ++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 impl/getcurrentthreadid.cpp create mode 100644 impl/getcurrentthreadid.h create mode 100644 tests/test-getcurrentthreadid.cpp diff --git a/impl/getcurrentthreadid.cpp b/impl/getcurrentthreadid.cpp new file mode 100644 index 0000000000..efd7a31361 --- /dev/null +++ b/impl/getcurrentthreadid.cpp @@ -0,0 +1,9 @@ +#include "getcurrentthreadid.h" +#include +#include + +HANDLE GetCurrentThreadId() +{ + pid_t tid = pthread_self(); + return reinterpret_cast(tid); +} diff --git a/impl/getcurrentthreadid.h b/impl/getcurrentthreadid.h new file mode 100644 index 0000000000..258c3c397f --- /dev/null +++ b/impl/getcurrentthreadid.h @@ -0,0 +1,10 @@ +#pragma once + +#include "pal.h" + +PAL_BEGIN_EXTERNC + +HANDLE GetCurrentThreadId(); + +PAL_END_EXTERNC + diff --git a/tests/test-getcurrentthreadid.cpp b/tests/test-getcurrentthreadid.cpp new file mode 100644 index 0000000000..7488d192dd --- /dev/null +++ b/tests/test-getcurrentthreadid.cpp @@ -0,0 +1,16 @@ +#include +#include "getcurrentthreadid.h" +#include + +TEST(GetCurrentThreadId,simple) +{ + const HANDLE currentThreadId = GetCurrentThreadId(); + const pid_t tid = pthread_self(); + + // first make sure that on this platform those types are of the same size + ASSERT_TRUE(sizeof(HANDLE) >= sizeof(pid_t)); + + // now compare the actual values + ASSERT_EQ(currentThreadId,reinterpret_cast(tid)); +} +