Pixar Arch 0.25.8
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 "pxr/arch/pxr.h"
15#include "pxr/arch/api.h"
16#include "pxr/arch/defines.h"
17
18// Needed for ARCH_SPIN_PAUSE on Windows in builds with precompiled
19// headers disabled.
20#ifdef ARCH_COMPILER_MSVC
21#include <intrin.h>
22#endif
23
24#include <thread>
25
26ARCH_NAMESPACE_OPEN_SCOPE
27
29ARCH_API bool ArchIsMainThread();
30
33ARCH_API std::thread::id ArchGetMainThreadId();
34
36#if defined(ARCH_CPU_INTEL)
37#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
38#define ARCH_SPIN_PAUSE() __builtin_ia32_pause()
39#elif defined(ARCH_COMPILER_MSVC)
40#define ARCH_SPIN_PAUSE() _mm_pause()
41#endif
42#elif defined(ARCH_CPU_ARM)
43#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
44#define ARCH_SPIN_PAUSE() asm volatile ("yield" ::: "memory")
45#elif defined(ARCH_COMPILER_MSVC)
46#define ARCH_SPIN_PAUSE() __yield();
47#endif
48#else
49#define ARCH_SPIN_PAUSE()
50#endif
51
52ARCH_NAMESPACE_CLOSE_SCOPE
53
54#endif // PXR_ARCH_THREADS_H
std::thread::id ArchGetMainThreadId()
Return the std::thread_id for the thread arch considers to be the "main" thread.
bool ArchIsMainThread()
Return true if the calling thread is the main thread, false otherwise.