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) 13 #include <common/include/WindowsWrapper.hpp> 14 #elif defined(__APPLE__) 15 #include "AvailabilityMacros.h" 16 #include <pthread.h> 17 #include <sys/syscall.h> 18 #include <sys/time.h> 19 #include <unistd.h> 20 #endif 21 22 namespace arm 23 { 24 namespace pipe 25 { 26 GetCurrentThreadId()27int GetCurrentThreadId() 28 { 29 #if !defined(ARMNN_DISABLE_THREADS) 30 #if defined(__linux__) 31 return static_cast<int>(gettid()); 32 #elif defined(_MSC_VER) 33 return ::GetCurrentThreadId(); 34 #elif defined(__APPLE__) 35 uint64_t threadId; 36 int iRet = pthread_threadid_np(NULL, &threadId); 37 if (iRet != 0) 38 { 39 return 0; 40 } 41 return static_cast<int>(threadId); 42 #endif 43 #else 44 return 0; 45 #endif 46 } 47 48 } // namespace pipe 49 } // namespace arm 50