Loading...
Searching...
No Matches
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 <string>
25#include <thread>
26
27PXR_NAMESPACE_OPEN_SCOPE
28
31ARCH_API bool ArchIsMainThread();
32
35ARCH_API std::thread::id ArchGetMainThreadId();
36
63ARCH_API bool ArchSetThisThreadName(char const *name);
64
78ARCH_API std::string ArchGetThisThreadName();
79
94
109
110
112#if defined(ARCH_CPU_INTEL)
113#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
114#define ARCH_SPIN_PAUSE() __builtin_ia32_pause()
115#elif defined(ARCH_COMPILER_MSVC)
116#define ARCH_SPIN_PAUSE() _mm_pause()
117#endif
118#elif defined(ARCH_CPU_ARM)
119#if defined(ARCH_COMPILER_GCC) || defined(ARCH_COMPILER_CLANG)
120#define ARCH_SPIN_PAUSE() asm volatile ("yield" ::: "memory")
121#elif defined(ARCH_COMPILER_MSVC)
122#define ARCH_SPIN_PAUSE() __yield();
123#endif
124#else
125#define ARCH_SPIN_PAUSE()
126#endif
127
128PXR_NAMESPACE_CLOSE_SCOPE
129
130#endif // PXR_BASE_ARCH_THREADS_H
ArchThreadPriority
Specifies a reduced-priority level for ArchSetThisThreadPriority().
Definition threads.h:84
@ ArchThreadPriorityLowest
Idle priority.
Definition threads.h:88
@ ArchThreadPriorityLow
Below-normal priority.
Definition threads.h:92
ARCH_API std::string ArchGetThisThreadName()
Return the name of the calling thread as a UTF-8 string, as previously set either by ArchSetThisThrea...
ARCH_API bool ArchSetThisThreadName(char const *name)
Set the name of the calling thread as UTF-8 text.
ARCH_API bool ArchSetThisThreadPriority(ArchThreadPriority priority)
Lower the priority of the calling thread to priority.
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.