开发者

Alternatives to GCC's new atomic integer operations

开发者 https://www.devze.com 2022-12-09 09:12 出处:网络
GCC\'s recent support for atomic operations (as described here) is great, and is 90% of what we need. Unfortunately, some of our products still need to run on Windows and so we need atomic integer ope

GCC's recent support for atomic operations (as described here) is great, and is 90% of what we need. Unfortunately, some of our products still need to run on Windows and so we need atomic integer operations for Windows as well.

In the past, we had custom assembly language implementations for all our platforms, but I'd like move all the *nix platforms over to the GCC supported operations and the thought c开发者_StackOverflowrossed my mind that perhaps there is also a more standard way to do this on Windows now as well...

Is there an officially sanctioned way of doing this on Windows (other than implementing them yourself in assembly language)?


You want the Interlocked functions.


It depends on which of those you need -- I don't think there's a (pre-built) implementation of every one of them on Windows (except possibly within gcc) but some of them have been around for quite a while. Windows has InterlockedIncrement, InterlockedDecrement, InterlockedAdd, InterlockedOr, InterlockedXor, and so on.


GLib provides some atomic operations, and they are known to run on windows. You can inspect the sources for ideas or directly pick the code you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消