[Mesa-dev] util/u_atomic: Add new macro p_atomic_add

Submitted by Jose Fonseca on Feb. 9, 2015, 4:19 p.m.

Details

Message ID 54D8DE07.9030600@vmware.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Jose Fonseca Feb. 9, 2015, 4:19 p.m.
On 06/02/15 22:39, Carl Worth wrote:
> On Fri, Feb 06 2015, Aaron Watry wrote:
>> Ignore me if this is a stupid question, but should those both be
>> sizeof(short)?  I'd expect the first to be sizeof(char).
>
> Not a stupid question. That was a copy-and-paste (kill-and-yank ?) bug
> of mine.
>
> Thanks for your attention to detail. I've fixed this in my tree.
>
> -Carl

Hi Carl,

Just one more tweak to InterlockedExchangeAdd64 as per patch attached. 
(The 64bit intrisicis are only available on 64-bits, but the 
non-intrisinc version is available everywhee.)

With that u_test_atomic builds and passes for me both on 32 and 64bits.

Sorry for the delay. And thanks for your help in keeping MSVC support on 
par.

Jose

Patch hide | download patch | download mbox

diff --git a/src/util/u_atomic.h b/src/util/u_atomic.h
index 4eb0ec6..0c43410 100644
--- a/src/util/u_atomic.h
+++ b/src/util/u_atomic.h
@@ -147,10 +147,10 @@  char _InterlockedCompareExchange8(char volatile *Destination8, char Exchange8, c
                                      (assert(!"should not get here"), 0))
 
 #define p_atomic_add(_v, _i) (\
-   sizeof *(_v) == sizeof(short)   ? _InterlockedExchangeAdd8 ((char *)   (_v), (_i)) : \
+   sizeof *(_v) == sizeof(char)    ? _InterlockedExchangeAdd8 ((char *)   (_v), (_i)) : \
    sizeof *(_v) == sizeof(short)   ? _InterlockedExchangeAdd16((short *)  (_v), (_i)) : \
    sizeof *(_v) == sizeof(long)    ? _InterlockedExchangeAdd  ((long *)   (_v), (_i)) : \
-   sizeof *(_v) == sizeof(__int64) ? _InterlockedExchangeAdd64((__int64 *)(_v), (_i)) : \
+   sizeof *(_v) == sizeof(__int64) ? InterlockedExchangeAdd64 ((__int64 *)(_v), (_i)) : \
                                      (assert(!"should not get here"), 0))
 
 #define p_atomic_cmpxchg(_v, _old, _new) (\

Comments

On Mon, Feb 09 2015, Jose Fonseca wrote:
> Just one more tweak to InterlockedExchangeAdd64 as per patch attached. 
..
> With that u_test_atomic builds and passes for me both on 32 and
> 64bits.

Excellent. Thanks for the fix and for the testing report.

> Sorry for the delay. And thanks for your help in keeping MSVC support on 
> par.

No problem with the delay. The timing is just right since I'm about to
send to the list an updated cache implementation that relies on this new
atomic_add, and that also includes some unit tests that I'm hoping
people can help test.

(But, fair warning, there's a bit of file-system manipulation code there
that I think will probably need some attention to work on non-Linux
systems.)

-Carl