blob: e5cf27622c7f5ecbd00645a0f885b7c5d0bf1691 [file] [log] [blame]
Jim Flynn1fdeb992020-07-09 07:28:37 +01001//
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 Hughes35c31c02020-08-17 15:47:20 +010013#include <common/include/WindowsWrapper.hpp>
Jim Flynn82262f52020-07-16 11:23:45 +010014#elif defined(__APPLE__)
15#include "AvailabilityMacros.h"
Keith Moka20b3122020-12-20 00:05:14 -080016#include <pthread.h>
Jim Flynn82262f52020-07-16 11:23:45 +010017#include <sys/syscall.h>
18#include <sys/time.h>
19#include <unistd.h>
Jim Flynn1fdeb992020-07-09 07:28:37 +010020#endif
21
22namespace armnnUtils
23{
24namespace Threads
25{
26
27int GetCurrentThreadId()
28{
29#if defined(__linux__)
30 return static_cast<int>(gettid());
31#elif defined(_MSC_VER)
32 return ::GetCurrentThreadId();
Jim Flynn82262f52020-07-16 11:23:45 +010033#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 Moka20b3122020-12-20 00:05:14 -080040 return static_cast<int>(threadId);
Jim Flynn1fdeb992020-07-09 07:28:37 +010041#endif
42}
43
44}
45}