Pixar Arch
Loading...
Searching...
No Matches
threads.h
Go to the documentation of this file.
1// Copyright 2016 Pixar
2//
3// Licensed under the terms set forth in the LICENSE.txt file available at
4// https://openusd.org/license.
5//
6// Modified by Jeremy Retailleau.
7
8#ifndef PXR_ARCH_THREADS_H
9#define PXR_ARCH_THREADS_H
10
13
14#include "./api.h"
15#include "./defines.h"
16
17// Needed for ARCH_SPIN_PAUSE on Windows in builds with precompiled
18// headers disabled.
19#ifdef ARCH_COMPILER_MSVC
20#include <intrin.h>
21#endif
22
23#include <thread>
24
25namespace pxr {
26
28ARCH_API bool ArchIsMainThread();
29
32ARCH_API std::thread::id ArchGetMainThreadId();
33
35#if defined(ARCH_CPU_INTEL)
36#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
37#define ARCH_SPIN_PAUSE() __builtin_ia32_pause()
38#elif defined(ARCH_COMPILER_MSVC)
39#define ARCH_SPIN_PAUSE() _mm_pause()
40#endif
41#elif defined(ARCH_CPU_ARM)
42#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
43#define ARCH_SPIN_PAUSE() asm volatile ("yield" ::: "memory")
44#elif defined(ARCH_COMPILER_MSVC)
45#define ARCH_SPIN_PAUSE() __yield();
46#endif
47#else
48#define ARCH_SPIN_PAUSE()
49#endif
50
51} // namespace pxr
52
53#endif // PXR_ARCH_THREADS_H
ARCH_API std::thread::id ArchGetMainThreadId()
Return the std::thread_id for the thread arch considers to be the "main" thread.
ARCH_API bool ArchIsMainThread()
Return true if the calling thread is the main thread, false otherwise.