@@ -749,9 +749,9 @@ class Thread
749
749
if ( WaitForSingleObject( m_hndl, INFINITE ) != WAIT_OBJECT_0 )
750
750
throw new ThreadException ( " Unable to join thread" );
751
751
// NOTE: m_addr must be cleared before m_hndl is closed to avoid
752
- // a race condition with isRunning. The operation is done
753
- // with atomicStore to prevent races .
754
- atomicStore(* cast (shared )&m_addr, m_addr.init);
752
+ // a race condition with isRunning. The operation is done
753
+ // with atomicStore to prevent compiler reordering .
754
+ atomicStore! (msync.raw) (* cast (shared )&m_addr, m_addr.init);
755
755
CloseHandle( m_hndl );
756
756
m_hndl = m_hndl.init;
757
757
}
@@ -763,7 +763,7 @@ class Thread
763
763
// which is normally called by the dtor. Setting m_addr
764
764
// to zero ensures that pthread_detach will not be called
765
765
// on object destruction.
766
- atomicStore( * cast ( shared )& m_addr, cast ( shared ) m_addr.init) ;
766
+ m_addr = m_addr.init;
767
767
}
768
768
if ( m_unhandled )
769
769
{
@@ -3057,7 +3057,6 @@ private
3057
3057
version ( Posix )
3058
3058
{
3059
3059
import core.sys.posix.unistd ; // for sysconf
3060
- import core.sys.posix.sys.mman ; // for mmap
3061
3060
3062
3061
version ( AsmX86_Windows ) {} else
3063
3062
version ( AsmX86_Posix ) {} else
@@ -3118,7 +3117,7 @@ private
3118
3117
assert ( obj );
3119
3118
3120
3119
assert ( Thread .getThis().m_curr is obj.m_ctxt );
3121
- atomicStore(* cast (shared )&Thread .getThis().m_lock, false );
3120
+ atomicStore! (msync.raw) (* cast (shared )&Thread .getThis().m_lock, false );
3122
3121
obj.m_ctxt.tstack = obj.m_ctxt.bstack;
3123
3122
obj.m_state = Fiber .State.EXEC ;
3124
3123
@@ -3804,7 +3803,10 @@ private:
3804
3803
m_size = sz;
3805
3804
}
3806
3805
else
3807
- { static if ( __traits( compiles, mmap ) )
3806
+ {
3807
+ import core.sys.posix.sys.mman ; // mmap
3808
+
3809
+ static if ( __traits( compiles, mmap ) )
3808
3810
{
3809
3811
m_pmem = mmap( null ,
3810
3812
sz,
@@ -3864,6 +3866,8 @@ private:
3864
3866
// global context list.
3865
3867
Thread .remove( m_ctxt );
3866
3868
3869
+ import core.sys.posix.sys.mman ; // munmap
3870
+
3867
3871
static if ( __traits( compiles, VirtualAlloc ) )
3868
3872
{
3869
3873
VirtualFree( m_pmem, 0 , MEM_RELEASE );
@@ -4138,15 +4142,15 @@ private:
4138
4142
// that it points to exactly the correct stack location so the
4139
4143
// successive pop operations will succeed.
4140
4144
* oldp = getStackTop();
4141
- atomicStore(* cast (shared )&tobj.m_lock, true );
4145
+ atomicStore! (msync.raw) (* cast (shared )&tobj.m_lock, true );
4142
4146
tobj.pushContext( m_ctxt );
4143
4147
4144
4148
fiber_switchContext( oldp, newp );
4145
4149
4146
4150
// NOTE: As above, these operations must be performed in a strict order
4147
4151
// to prevent Bad Things from happening.
4148
4152
tobj.popContext();
4149
- atomicStore(* cast (shared )&tobj.m_lock, false );
4153
+ atomicStore! (msync.raw) (* cast (shared )&tobj.m_lock, false );
4150
4154
tobj.m_curr.tstack = tobj.m_curr.bstack;
4151
4155
}
4152
4156
@@ -4172,7 +4176,7 @@ private:
4172
4176
// that it points to exactly the correct stack location so the
4173
4177
// successive pop operations will succeed.
4174
4178
* oldp = getStackTop();
4175
- atomicStore(* cast (shared )&tobj.m_lock, true );
4179
+ atomicStore! (msync.raw) (* cast (shared )&tobj.m_lock, true );
4176
4180
4177
4181
fiber_switchContext( oldp, newp );
4178
4182
@@ -4182,7 +4186,7 @@ private:
4182
4186
// executing here may be different from the one above, so get the
4183
4187
// current thread handle before unlocking, etc.
4184
4188
tobj = Thread .getThis();
4185
- atomicStore(* cast (shared )&tobj.m_lock, false );
4189
+ atomicStore! (msync.raw) (* cast (shared )&tobj.m_lock, false );
4186
4190
tobj.m_curr.tstack = tobj.m_curr.bstack;
4187
4191
}
4188
4192
}
0 commit comments