Skip to content

Commit 28c7634

Browse files
author
Alex Rønne Petersen
committed
Merge pull request #1 from dawgfoto/remove-deprecated
loose memory barriers
2 parents f1d364e + 63d91f2 commit 28c7634

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/core/thread.d

+15-11
Original file line numberDiff line numberDiff line change
@@ -749,9 +749,9 @@ class Thread
749749
if( WaitForSingleObject( m_hndl, INFINITE ) != WAIT_OBJECT_0 )
750750
throw new ThreadException( "Unable to join thread" );
751751
// 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);
755755
CloseHandle( m_hndl );
756756
m_hndl = m_hndl.init;
757757
}
@@ -763,7 +763,7 @@ class Thread
763763
// which is normally called by the dtor. Setting m_addr
764764
// to zero ensures that pthread_detach will not be called
765765
// on object destruction.
766-
atomicStore(*cast(shared)&m_addr, cast(shared)m_addr.init);
766+
m_addr = m_addr.init;
767767
}
768768
if( m_unhandled )
769769
{
@@ -3057,7 +3057,6 @@ private
30573057
version( Posix )
30583058
{
30593059
import core.sys.posix.unistd; // for sysconf
3060-
import core.sys.posix.sys.mman; // for mmap
30613060

30623061
version( AsmX86_Windows ) {} else
30633062
version( AsmX86_Posix ) {} else
@@ -3118,7 +3117,7 @@ private
31183117
assert( obj );
31193118

31203119
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);
31223121
obj.m_ctxt.tstack = obj.m_ctxt.bstack;
31233122
obj.m_state = Fiber.State.EXEC;
31243123

@@ -3804,7 +3803,10 @@ private:
38043803
m_size = sz;
38053804
}
38063805
else
3807-
{ static if( __traits( compiles, mmap ) )
3806+
{
3807+
import core.sys.posix.sys.mman; // mmap
3808+
3809+
static if( __traits( compiles, mmap ) )
38083810
{
38093811
m_pmem = mmap( null,
38103812
sz,
@@ -3864,6 +3866,8 @@ private:
38643866
// global context list.
38653867
Thread.remove( m_ctxt );
38663868

3869+
import core.sys.posix.sys.mman; // munmap
3870+
38673871
static if( __traits( compiles, VirtualAlloc ) )
38683872
{
38693873
VirtualFree( m_pmem, 0, MEM_RELEASE );
@@ -4138,15 +4142,15 @@ private:
41384142
// that it points to exactly the correct stack location so the
41394143
// successive pop operations will succeed.
41404144
*oldp = getStackTop();
4141-
atomicStore(*cast(shared)&tobj.m_lock, true);
4145+
atomicStore!(msync.raw)(*cast(shared)&tobj.m_lock, true);
41424146
tobj.pushContext( m_ctxt );
41434147

41444148
fiber_switchContext( oldp, newp );
41454149

41464150
// NOTE: As above, these operations must be performed in a strict order
41474151
// to prevent Bad Things from happening.
41484152
tobj.popContext();
4149-
atomicStore(*cast(shared)&tobj.m_lock, false);
4153+
atomicStore!(msync.raw)(*cast(shared)&tobj.m_lock, false);
41504154
tobj.m_curr.tstack = tobj.m_curr.bstack;
41514155
}
41524156

@@ -4172,7 +4176,7 @@ private:
41724176
// that it points to exactly the correct stack location so the
41734177
// successive pop operations will succeed.
41744178
*oldp = getStackTop();
4175-
atomicStore(*cast(shared)&tobj.m_lock, true);
4179+
atomicStore!(msync.raw)(*cast(shared)&tobj.m_lock, true);
41764180

41774181
fiber_switchContext( oldp, newp );
41784182

@@ -4182,7 +4186,7 @@ private:
41824186
// executing here may be different from the one above, so get the
41834187
// current thread handle before unlocking, etc.
41844188
tobj = Thread.getThis();
4185-
atomicStore(*cast(shared)&tobj.m_lock, false);
4189+
atomicStore!(msync.raw)(*cast(shared)&tobj.m_lock, false);
41864190
tobj.m_curr.tstack = tobj.m_curr.bstack;
41874191
}
41884192
}

0 commit comments

Comments
 (0)