Merge pull request 11 from feature/getcurrentthreadid into develop
This commit is contained in:
commit
82d119f94c
9
src/impl/getcurrentthreadid.cpp
Normal file
9
src/impl/getcurrentthreadid.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "getcurrentthreadid.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
HANDLE GetCurrentThreadId()
|
||||||
|
{
|
||||||
|
pid_t tid = pthread_self();
|
||||||
|
return reinterpret_cast<HANDLE>(tid);
|
||||||
|
}
|
10
src/impl/getcurrentthreadid.h
Normal file
10
src/impl/getcurrentthreadid.h
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "pal.h"
|
||||||
|
|
||||||
|
PAL_BEGIN_EXTERNC
|
||||||
|
|
||||||
|
HANDLE GetCurrentThreadId();
|
||||||
|
|
||||||
|
PAL_END_EXTERNC
|
||||||
|
|
16
src/tests/test-getcurrentthreadid.cpp
Normal file
16
src/tests/test-getcurrentthreadid.cpp
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include "getcurrentthreadid.h"
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
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<HANDLE>(tid));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user