xref: /aosp_15_r20/external/armnn/profiling/common/src/Threads.cpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
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()27 int 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