Repository navigation
[linux-port] Thread-safe increment/decrement - #201
Conversation
|
It's worth noting that the critical section changes to LLVM code actually revert changes made as part of the HLSL project for reasons poorly specified in the original change especially since none of their code made use of the functions in question. |
|
❌ Build DirectXShaderCompiler 1.0.68 failed (commit 6fcdbc6145 by @pow2clk) |
|
❌ Build DirectXShaderCompiler 1.0.69 failed (commit be740accec by @pow2clk) |
InterlockedIncrement and InterlockedDecrement are atomic operations to increment or decrement the value pointed to by the pointer parameter and return the same. Currently they are implemented as simple addition operations in WinMacros.h for non-win32 platforms which works well enough, but wasn't really the original intent. There are already platform abstractions available to LLVM in Atomics.h. This change leverages them to implement the same functionality in a platform-agnostic way. Mostly it's just a matter of swapping InterlockedIncrement for AtomicIncrement. Fixes half of google#198
|
I backed away from the critical section portion for now. There are some complications on windows and linux regarding how everything is initialized and allocated. It could be fixed by just making everything static, but that's a bit ugly and invasive in the LLVM code. I'm going to poke at the startup mechanism on each a bit more to see if there is a better solution. In the meantime, I can stop tripping over these changes. |
|
✅ Build DirectXShaderCompiler 1.0.72 completed (commit 715edb9995 by @pow2clk) |
ehsannas
left a comment
There was a problem hiding this comment.
LGTM. I'm hoping MS is open to using llvm::sys::AtomicIncrement. I think it's reasonable.
|
|
||
|
|
||
| // TODO (ehsann): These are not atomic. | ||
| #define InterlockedIncrement(x) ++*x |
|
I hope they are too. That's the big unknown. The same potential for turmoil will be present with the followup for critical sections. It looks like they tried to make the common code work there but gave up in the end. So I consider that an encouraging data point. |
antiagainst
left a comment
There was a problem hiding this comment.
Cool stuff! I think this one is self-contained enough that we can also open a pull request against upstream. llvm::sys::Atomic*() is merely wrapping around Interlocked*() on Windows, so it should be okay.
InterlockedIncrement and InterlockedDecrement are atomic operations to
increment or decrement the value pointed to by the pointer parameter and
return the same. Currently they are implemented as simple addition
operations in WinMacros.h for non-win32 platforms which works well
enough, but wasn't really the original intent.
There are already platform abstractions available to LLVM in Atomics.h.
This change leverages them to implement the same functionality in a
platform-agnostic way. Mostly it's just a matter of swapping
InterlockedIncrement for AtomicIncrement.
Fixes half of #198