forked from doitsujin/dxvk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[util] Implement thread helpers on non-Windows platforms
- Loading branch information
Showing
4 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters