HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 
10 /// \file arch/threads.h
11 /// \ingroup group_arch_Multithreading
12 /// Architecture-specific thread function calls.
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 
27 
28 /// Return true if the calling thread is the main thread, false otherwise.
29 /// \ingroup group_arch_Multithreading
31 
32 /// Return the std::thread_id for the thread arch considers to be the "main"
33 /// thread.
35 
36 /// ARCH_SPIN_PAUSE -- 'pause' on x86, 'yield' on arm.
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 
54 
55 #endif // PXR_BASE_ARCH_THREADS_H
GLuint id
Definition: glcorearb.h:655
ARCH_API std::thread::id ArchGetMainThreadId()
PXR_NAMESPACE_OPEN_SCOPE ARCH_API bool ArchIsMainThread()
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
#define ARCH_API
Definition: api.h:23