diff options
Diffstat (limited to 'profiling/common/src/Threads.cpp')
-rw-r--r-- | profiling/common/src/Threads.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/profiling/common/src/Threads.cpp b/profiling/common/src/Threads.cpp new file mode 100644 index 0000000000..10533b77b9 --- /dev/null +++ b/profiling/common/src/Threads.cpp @@ -0,0 +1,45 @@ +// +// Copyright © 2020 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#include "Threads.hpp" + +#if defined(__linux__) +#include <unistd.h> +#include <sys/syscall.h> +#define gettid() syscall(SYS_gettid) +#elif defined(_MSC_VER) +#include <common/include/WindowsWrapper.hpp> +#elif defined(__APPLE__) +#include "AvailabilityMacros.h" +#include <pthread.h> +#include <sys/syscall.h> +#include <sys/time.h> +#include <unistd.h> +#endif + +namespace arm +{ +namespace pipe +{ + +int GetCurrentThreadId() +{ +#if defined(__linux__) + return static_cast<int>(gettid()); +#elif defined(_MSC_VER) + return ::GetCurrentThreadId(); +#elif defined(__APPLE__) + uint64_t threadId; + int iRet = pthread_threadid_np(NULL, &threadId); + if (iRet != 0) + { + return 0; + } + return static_cast<int>(threadId); +#endif +} + +} // namespace pipe +} // namespace arm |