Mesa (master): util/u_atomic: Add _InterlockedExchangeAdd8/ 16 for older MSVC.
Jose Fonseca
jrfonseca at kemper.freedesktop.org
Thu Feb 12 19:38:13 UTC 2015
Module: Mesa
Branch: master
Commit: 531d47baa8f755a688c77aec488742ee7d491014
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=531d47baa8f755a688c77aec488742ee7d491014
Author: Jose Fonseca <jfonseca at vmware.com>
Date: Wed Feb 11 15:30:39 2015 +0000
util/u_atomic: Add _InterlockedExchangeAdd8/16 for older MSVC.
We need to build certain parts of Mesa (namely gallium, llvmpipe, and
therefore util) with Windows SDK 7.0.7600, which includes MSVC 2008.
Reviewed-by: Brian Paul <brianp at vmware.com>
Reviewed-by: Roland Scheidegger <sroland at vmware.com>
---
src/util/u_atomic.h | 37 +++++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)
diff --git a/src/util/u_atomic.h b/src/util/u_atomic.h
index e123e17..728322b 100644
--- a/src/util/u_atomic.h
+++ b/src/util/u_atomic.h
@@ -88,9 +88,9 @@
#if _MSC_VER < 1600
-/* Implement _InterlockedCompareExchange8 in terms of InterlockedCompareExchange16 */
-static __inline
-char _InterlockedCompareExchange8(char volatile *Destination8, char Exchange8, char Comparand8)
+/* Implement _InterlockedCompareExchange8 in terms of _InterlockedCompareExchange16 */
+static __inline char
+_InterlockedCompareExchange8(char volatile *Destination8, char Exchange8, char Comparand8)
{
INT_PTR DestinationAddr = (INT_PTR)Destination8;
short volatile *Destination16 = (short volatile *)(DestinationAddr & ~1);
@@ -103,7 +103,7 @@ char _InterlockedCompareExchange8(char volatile *Destination8, char Exchange8, c
* neighboring byte untouched */
short Exchange16 = (Initial16 & ~Mask8) | ((short)Exchange8 << Shift8);
short Comparand16 = Initial16;
- short Initial16 = InterlockedCompareExchange16(Destination16, Exchange16, Comparand16);
+ short Initial16 = _InterlockedCompareExchange16(Destination16, Exchange16, Comparand16);
if (Initial16 == Comparand16) {
/* succeeded */
return Comparand8;
@@ -114,6 +114,35 @@ char _InterlockedCompareExchange8(char volatile *Destination8, char Exchange8, c
return Initial8;
}
+/* Implement _InterlockedExchangeAdd16 in terms of _InterlockedCompareExchange16 */
+static __inline short
+_InterlockedExchangeAdd16(short volatile *Addend, short Value)
+{
+ short Initial = *Addend;
+ short Comparand;
+ do {
+ short Exchange = Initial + Value;
+ Comparand = Initial;
+ /* if *Addend==Comparand then *Addend=Exchange, return original *Addend */
+ Initial = _InterlockedCompareExchange16(Addend, Exchange, Comparand);
+ } while(Initial != Comparand);
+ return Comparand;
+}
+
+/* Implement _InterlockedExchangeAdd8 in terms of _InterlockedCompareExchange8 */
+static __inline char
+_InterlockedExchangeAdd8(char volatile *Addend, char Value)
+{
+ char Initial = *Addend;
+ char Comparand;
+ do {
+ char Exchange = Initial + Value;
+ Comparand = Initial;
+ Initial = _InterlockedCompareExchange8(Addend, Exchange, Comparand);
+ } while(Initial != Comparand);
+ return Comparand;
+}
+
#endif /* _MSC_VER < 1600 */
/* MSVC supports decltype keyword, but it's only supported on C++ and doesn't
More information about the mesa-commit
mailing list