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 | |
Rob Hughes | 9542f90 | 2021-07-14 09:48:54 +0100 | [diff] [blame] | 6 | #include <armnnUtils/Threads.hpp> |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 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" |
Keith Mok | a20b312 | 2020-12-20 00:05:14 -0800 | [diff] [blame] | 16 | #include <pthread.h> |
Jim Flynn | 82262f5 | 2020-07-16 11:23:45 +0100 | [diff] [blame] | 17 | #include <sys/syscall.h> |
| 18 | #include <sys/time.h> |
| 19 | #include <unistd.h> |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 20 | #endif |
| 21 | |
| 22 | namespace armnnUtils |
| 23 | { |
| 24 | namespace Threads |
| 25 | { |
| 26 | |
| 27 | int GetCurrentThreadId() |
| 28 | { |
| 29 | #if defined(__linux__) |
| 30 | return static_cast<int>(gettid()); |
| 31 | #elif defined(_MSC_VER) |
| 32 | return ::GetCurrentThreadId(); |
Jim Flynn | 82262f5 | 2020-07-16 11:23:45 +0100 | [diff] [blame] | 33 | #elif defined(__APPLE__) |
| 34 | uint64_t threadId; |
| 35 | int iRet = pthread_threadid_np(NULL, &threadId); |
| 36 | if (iRet != 0) |
| 37 | { |
| 38 | return 0; |
| 39 | } |
Keith Mok | a20b312 | 2020-12-20 00:05:14 -0800 | [diff] [blame] | 40 | return static_cast<int>(threadId); |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 41 | #endif |
| 42 | } |
| 43 | |
| 44 | } |
| 45 | } |