Mercurial > projects > ldc
comparison runtime/llvmdc.diff @ 615:c60e122f4ada
Fix atomicIncr and atomicDecr. Probably.
The unittest for tango.core.Atomic now passes.
author | Christian Kamm <kamm incasoftware de> |
---|---|
date | Sun, 21 Sep 2008 18:41:27 +0200 |
parents | 19cbc612380a |
children | 79cbe5034fec |
comparison
equal
deleted
inserted
replaced
614:452e6e2618bf | 615:c60e122f4ada |
---|---|
246 /** | 246 /** |
247 Index: tango/core/Atomic.d | 247 Index: tango/core/Atomic.d |
248 =================================================================== | 248 =================================================================== |
249 --- tango/core/Atomic.d (revision 3939) | 249 --- tango/core/Atomic.d (revision 3939) |
250 +++ tango/core/Atomic.d (working copy) | 250 +++ tango/core/Atomic.d (working copy) |
251 @@ -270,6 +270,173 @@ | 251 @@ -270,6 +270,167 @@ |
252 | 252 |
253 | 253 |
254 //////////////////////////////////////////////////////////////////////////////// | 254 //////////////////////////////////////////////////////////////////////////////// |
255 +// LLVMDC Atomics Implementation | 255 +// LLVMDC Atomics Implementation |
256 +//////////////////////////////////////////////////////////////////////////////// | 256 +//////////////////////////////////////////////////////////////////////////////// |
371 + | 371 + |
372 + T atomicIncrement( ref T val ) | 372 + T atomicIncrement( ref T val ) |
373 + { | 373 + { |
374 + static if (isPointerType!(T)) | 374 + static if (isPointerType!(T)) |
375 + { | 375 + { |
376 + return cast(T)llvm_atomic_load_add!(size_t)(cast(size_t*)&val, 1); | 376 + llvm_atomic_load_add!(size_t)(cast(size_t*)&val, 1); |
377 + } | 377 + } |
378 + else static if (is(T == bool)) | |
379 + { | |
380 + return llvm_atomic_load_add!(ubyte)(cast(ubyte*)&val, 1)?1:0; | |
381 + } | |
382 + else | 378 + else |
383 + { | 379 + { |
384 + return llvm_atomic_load_add!(T)(&val, cast(T)1); | 380 + llvm_atomic_load_add!(T)(&val, cast(T)1); |
385 + } | 381 + } |
382 + return val; | |
386 + } | 383 + } |
387 + } | 384 + } |
388 + | 385 + |
389 + | 386 + |
390 + //////////////////////////////////////////////////////////////////////////// | 387 + //////////////////////////////////////////////////////////////////////////// |
402 + | 399 + |
403 + T atomicDecrement( ref T val ) | 400 + T atomicDecrement( ref T val ) |
404 + { | 401 + { |
405 + static if (isPointerType!(T)) | 402 + static if (isPointerType!(T)) |
406 + { | 403 + { |
407 + return cast(T)llvm_atomic_load_sub!(size_t)(cast(size_t*)&val, 1); | 404 + llvm_atomic_load_sub!(size_t)(cast(size_t*)&val, 1); |
408 + } | 405 + } |
409 + else static if (is(T == bool)) | |
410 + { | |
411 + return llvm_atomic_load_sub!(ubyte)(cast(ubyte*)&val, 1)?1:0; | |
412 + } | |
413 + else | 406 + else |
414 + { | 407 + { |
415 + return llvm_atomic_load_sub!(T)(&val, cast(T)1); | 408 + llvm_atomic_load_sub!(T)(&val, cast(T)1); |
416 + } | 409 + } |
410 + return val; | |
417 + } | 411 + } |
418 + } | 412 + } |
419 +} | 413 +} |
420 + | 414 + |
421 +//////////////////////////////////////////////////////////////////////////////// | 415 +//////////////////////////////////////////////////////////////////////////////// |