Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "Threads.hpp" |
| 7 | |
| 8 | #if defined(__linux__) |
| 9 | #include <unistd.h> |
| 10 | #include <sys/syscall.h> |
| 11 | #define gettid() syscall(SYS_gettid) |
| 12 | #elif defined(_MSC_VER) |
Rob Hughes | 35c31c0 | 2020-08-17 15:47:20 +0100 | [diff] [blame] | 13 | #include <common/include/WindowsWrapper.hpp> |
Jim Flynn | 82262f5 | 2020-07-16 11:23:45 +0100 | [diff] [blame] | 14 | #elif defined(__APPLE__) |
| 15 | #include "AvailabilityMacros.h" |
| 16 | #include <sys/syscall.h> |
| 17 | #include <sys/time.h> |
| 18 | #include <unistd.h> |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 19 | #endif |
| 20 | |
| 21 | namespace armnnUtils |
| 22 | { |
| 23 | namespace Threads |
| 24 | { |
| 25 | |
| 26 | int GetCurrentThreadId() |
| 27 | { |
| 28 | #if defined(__linux__) |
| 29 | return static_cast<int>(gettid()); |
| 30 | #elif defined(_MSC_VER) |
| 31 | return ::GetCurrentThreadId(); |
Jim Flynn | 82262f5 | 2020-07-16 11:23:45 +0100 | [diff] [blame] | 32 | #elif defined(__APPLE__) |
| 33 | uint64_t threadId; |
| 34 | int iRet = pthread_threadid_np(NULL, &threadId); |
| 35 | if (iRet != 0) |
| 36 | { |
| 37 | return 0; |
| 38 | } |
| 39 | return threadId; |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 40 | #endif |
| 41 | } |
| 42 | |
| 43 | } |
| 44 | } |