Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/doitsujin/dxvk.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoshua Ashton <joshua@froggi.es>2022-04-18 02:29:07 +0300
committerJoshua Ashton <joshua@froggi.es>2022-04-18 02:55:40 +0300
commit8d7af0dc5db4b27c346f83ce6858b86f9b74e819 (patch)
tree8608ebe66e7392a70d0920653dd136aab1809440
parent736f743ae41d6a2a37b71a11eaf5b7ee68e15c65 (diff)
[util] Implement thread helpers on non-Windows platformsimplement-thread-on-non-windows
-rw-r--r--src/util/meson.build2
-rw-r--r--src/util/sync/sync_recursive.cpp2
-rw-r--r--src/util/thread.cpp27
-rw-r--r--src/util/thread.h20
4 files changed, 50 insertions, 1 deletions
diff --git a/src/util/meson.build b/src/util/meson.build
index 058b9686..34da01ee 100644
--- a/src/util/meson.build
+++ b/src/util/meson.build
@@ -8,6 +8,8 @@ util_src = files([
'util_monitor.cpp',
'util_shared_res.cpp',
+ 'thread.cpp',
+
'com/com_guid.cpp',
'com/com_private_data.cpp',
diff --git a/src/util/sync/sync_recursive.cpp b/src/util/sync/sync_recursive.cpp
index ee6a1265..85af6137 100644
--- a/src/util/sync/sync_recursive.cpp
+++ b/src/util/sync/sync_recursive.cpp
@@ -17,7 +17,7 @@ namespace dxvk::sync {
bool RecursiveSpinlock::try_lock() {
- uint32_t threadId = GetCurrentThreadId();
+ uint32_t threadId = dxvk::this_thread::get_id();
uint32_t expected = 0;
bool status = m_owner.compare_exchange_weak(
diff --git a/src/util/thread.cpp b/src/util/thread.cpp
new file mode 100644
index 00000000..eed45d34
--- /dev/null
+++ b/src/util/thread.cpp
@@ -0,0 +1,27 @@
+#include "thread.h"
+#include "util_likely.h"
+
+#include <atomic>
+
+#ifndef _WIN32
+
+namespace dxvk::this_thread {
+
+ static std::atomic<uint32_t> g_threadCtr = { 0u };
+ static thread_local uint32_t g_threadId = 0u;
+
+ // This implementation returns thread ids unique to the current instance.
+ // ie. if you use this across multiple .so's then you might get conflicting ids.
+ //
+ // This isn't an issue for us, as it is only used by the spinlock implementation,
+ // but may be for you if you use this elsewhere.
+ uint32_t get_id() {
+ if (unlikely(!g_threadId))
+ g_threadId = ++g_threadCtr;
+
+ return g_threadId;
+ }
+
+}
+
+#endif
diff --git a/src/util/thread.h b/src/util/thread.h
index 28aeca8a..1299a715 100644
--- a/src/util/thread.h
+++ b/src/util/thread.h
@@ -14,6 +14,7 @@
namespace dxvk {
+#ifdef _WIN32
/**
* \brief Thread priority
*/
@@ -147,6 +148,10 @@ namespace dxvk {
inline void yield() {
SwitchToThread();
}
+
+ inline uint32_t get_id() {
+ return uint32_t(GetCurrentThreadId());
+ }
}
@@ -323,4 +328,19 @@ namespace dxvk {
};
+#else
+ using mutex = std::mutex;
+ using thread = std::thread;
+ using recursive_mutex = std::recursive_mutex;
+ using condition_variable = std::condition_variable;
+
+ namespace this_thread {
+ inline void yield() {
+ std::this_thread::yield();
+ }
+
+ uint32_t get_id();
+ }
+#endif
+
}