Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Replace naked Read-Modify-Write ops on shared values which will be ba…
Browse files Browse the repository at this point in the history
…nned.
  • Loading branch information
AndrejMitrovic committed Feb 3, 2014
1 parent eeac848 commit 2cd03b0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/core/atomic.d
Expand Up @@ -69,7 +69,7 @@ version( CoreDdoc )
* The result of the operation.
*/
HeadUnshared!(T) atomicOp(string op, T, V1)( ref shared T val, V1 mod ) nothrow
if( __traits( compiles, mixin( "val" ~ op ~ "mod" ) ) )
if( __traits( compiles, mixin( "*cast(T*)&val" ~ op ~ "mod" ) ) )
{
return HeadUnshared!(T).init;
}
Expand Down Expand Up @@ -155,7 +155,7 @@ version( CoreDdoc )
else version( AsmX86_32 )
{
HeadUnshared!(T) atomicOp(string op, T, V1)( ref shared T val, V1 mod ) nothrow
if( __traits( compiles, mixin( "val" ~ op ~ "mod" ) ) )
if( __traits( compiles, mixin( "*cast(T*)&val" ~ op ~ "mod" ) ) )
in
{
// NOTE: 32 bit x86 systems support 8 byte CAS, which only requires
Expand Down Expand Up @@ -633,7 +633,7 @@ else version( AsmX86_32 )
else version( AsmX86_64 )
{
HeadUnshared!(T) atomicOp(string op, T, V1)( ref shared T val, V1 mod ) nothrow
if( __traits( compiles, mixin( "val" ~ op ~ "mod" ) ) )
if( __traits( compiles, mixin( "*cast(T*)&val" ~ op ~ "mod" ) ) )
in
{
// NOTE: 32 bit x86 systems support 8 byte CAS, which only requires
Expand Down
5 changes: 3 additions & 2 deletions src/rt/dmain2.d
Expand Up @@ -16,6 +16,7 @@ private
import rt.memory;
import rt.sections;
import rt.util.string;
import core.atomic;
import core.stdc.stddef;
import core.stdc.stdlib;
import core.stdc.string;
Expand Down Expand Up @@ -152,7 +153,7 @@ extern (C) int rt_init()
initialize different D libraries without knowing about the
shared druntime. Also we need to attach any thread that calls
rt_init. */
if (_initCount++) return 1;
if (atomicOp!"+="(_initCount, 1) > 1) return 1;

_STI_monitor_staticctor();
_STI_critical_init();
Expand Down Expand Up @@ -182,7 +183,7 @@ extern (C) int rt_init()
extern (C) int rt_term()
{
if (!_initCount) return 0; // was never initialized
if (--_initCount) return 1;
if (atomicOp!"-="(_initCount, 1)) return 1;

try
{
Expand Down

0 comments on commit 2cd03b0

Please sign in to comment.