blob: 64a84812d2a8cccee89dbe5e7617c57e26852d63 [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"
16#include <sys/syscall.h>
17#include <sys/time.h>
18#include <unistd.h>
Jim Flynn1fdeb992020-07-09 07:28:37 +010019#endif
20
21namespace armnnUtils
22{
23namespace Threads
24{
25
26int GetCurrentThreadId()
27{
28#if defined(__linux__)
29 return static_cast<int>(gettid());
30#elif defined(_MSC_VER)
31 return ::GetCurrentThreadId();
Jim Flynn82262f52020-07-16 11:23:45 +010032#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 Flynn1fdeb992020-07-09 07:28:37 +010040#endif
41}
42
43}
44}