mirror of
https://github.com/yse/easy_profiler.git
synced 2024-12-27 08:41:02 +08:00
Few more MacOS fixes.
Thread id changed to size_t, required for MacOS because older versions do not have integral thread ids and we must use a pointer returned by pthread_self()/
This commit is contained in:
parent
a01187cf55
commit
08ae417931
@ -204,7 +204,7 @@ int EasySocket::send(const void *buf, size_t nbyte)
|
||||
{
|
||||
if(!checkSocket(m_replySocket)) return -1;
|
||||
int res = 0;
|
||||
#ifdef _WIN32
|
||||
#if defined(_WIN32) || defined(__APPLE__)
|
||||
res = ::send(m_replySocket, (const char*)buf, (int)nbyte, 0);
|
||||
#else
|
||||
res = ::send(m_replySocket,buf,nbyte,MSG_NOSIGNAL);
|
||||
|
@ -445,7 +445,7 @@ namespace profiler {
|
||||
const uint16_t DEFAULT_PORT = EASY_DEFAULT_PORT;
|
||||
|
||||
typedef uint64_t timestamp_t;
|
||||
typedef uint32_t thread_id_t;
|
||||
typedef size_t thread_id_t;
|
||||
typedef uint32_t block_id_t;
|
||||
|
||||
enum BlockType : uint8_t
|
||||
|
@ -61,6 +61,9 @@ The Apache License, Version 2.0 (the "License");
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <Windows.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <pthread.h>
|
||||
#include <Availability.h>
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
@ -73,13 +76,22 @@ The Apache License, Version 2.0 (the "License");
|
||||
#undef max
|
||||
#endif
|
||||
|
||||
inline uint32_t getCurrentThreadId()
|
||||
inline profiler::thread_id_t getCurrentThreadId()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return (uint32_t)::GetCurrentThreadId();
|
||||
return (profiler::thread_id_t)::GetCurrentThreadId();
|
||||
#elif defined(__APPLE__)
|
||||
# if (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_6) || \
|
||||
(defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0)
|
||||
EASY_THREAD_LOCAL static uint64_t _id = 0;
|
||||
if (!_id)
|
||||
pthread_threadid_np(NULL, &_id);
|
||||
return (profiler::thread_id_t)_id;
|
||||
# else
|
||||
return (profiler::thread_id_t)pthread_self();
|
||||
# endif
|
||||
#else
|
||||
EASY_THREAD_LOCAL static const pid_t x = syscall(__NR_gettid);
|
||||
EASY_THREAD_LOCAL static const uint32_t _id = (uint32_t)x;//std::hash<std::thread::id>()(std::this_thread::get_id());
|
||||
EASY_THREAD_LOCAL static const profiler::thread_id_t _id = (profiler::thread_id_t)syscall(__NR_gettid);
|
||||
return _id;
|
||||
#endif
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user