All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
threads.h
Go to the documentation of this file.
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_BASE_ARCH_THREADS_H
8#define PXR_BASE_ARCH_THREADS_H
9
13
14#include "pxr/pxr.h"
15#include "pxr/base/arch/api.h"
16#include "pxr/base/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
26PXR_NAMESPACE_OPEN_SCOPE
27
30ARCH_API bool ArchIsMainThread();
31
34ARCH_API std::thread::id ArchGetMainThreadId();
35
37#if defined(ARCH_CPU_INTEL)
38#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
39#define ARCH_SPIN_PAUSE() __builtin_ia32_pause()
40#elif defined(ARCH_COMPILER_MSVC)
41#define ARCH_SPIN_PAUSE() _mm_pause()
42#endif
43#elif defined(ARCH_CPU_ARM)
44#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
45#define ARCH_SPIN_PAUSE() asm volatile ("yield" ::: "memory")
46#elif defined(ARCH_COMPILER_MSVC)
47#define ARCH_SPIN_PAUSE() __yield();
48#endif
49#else
50#define ARCH_SPIN_PAUSE()
51#endif
52
53PXR_NAMESPACE_CLOSE_SCOPE
54
55#endif // PXR_BASE_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.