[vmkit-commits] [vmkit] r109982 - in /vmkit/trunk: include/mvm/Threads/Thread.h lib/Mvm/CommonThread/CollectionRV.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Sun Aug 1 09:01:21 PDT 2010
Author: geoffray
Date: Sun Aug 1 11:01:21 2010
New Revision: 109982
URL: http://llvm.org/viewvc/llvm-project?rev=109982&view=rev
Log:
Emit atomic operations when changing states in thread.
Modified:
vmkit/trunk/include/mvm/Threads/Thread.h
vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp
Modified: vmkit/trunk/include/mvm/Threads/Thread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/Thread.h?rev=109982&r1=109981&r2=109982&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/Threads/Thread.h (original)
+++ vmkit/trunk/include/mvm/Threads/Thread.h Sun Aug 1 11:01:21 2010
@@ -251,7 +251,8 @@
++level;
void* temp = __builtin_frame_address(0);
while (level--) temp = ((void**)temp)[0];
- lastSP = temp;
+ // The cas is not necessary, but it does a memory barrier.
+ __sync_bool_compare_and_swap(&lastSP, 0, temp);
if (doYield) joinRVBeforeEnter();
assert(lastSP && "No last SP when entering uncooperative code");
}
@@ -262,7 +263,8 @@
if (isMvmThread()) {
if (!inRV) {
assert(!lastSP && "SP already set when entering uncooperative code");
- lastSP = SP;
+ // The cas is not necessary, but it does a memory barrier.
+ __sync_bool_compare_and_swap(&lastSP, 0, SP);
if (doYield) joinRVBeforeEnter();
assert(lastSP && "No last SP when entering uncooperative code");
}
@@ -273,7 +275,8 @@
if (isMvmThread()) {
if (!inRV) {
assert(lastSP && "No last SP when leaving uncooperative code");
- lastSP = 0;
+ // The cas is not necessary, but it does a memory barrier.
+ __sync_bool_compare_and_swap(&lastSP, lastSP, 0);
// A rendezvous has just been initiated, join it.
if (doYield) joinRVAfterLeave();
assert(!lastSP && "SP has a value after leaving uncooperative code");
Modified: vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp?rev=109982&r1=109981&r2=109982&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp Sun Aug 1 11:01:21 2010
@@ -59,8 +59,10 @@
assert(!cur->joinedRV);
cur = (mvm::Thread*)cur->next();
} while (cur != self);
+
+ // The CAS is not necessary but it does a memory barrier.
+ __sync_bool_compare_and_swap(&(self->joinedRV), false, true);
- self->joinedRV = true;
// Lookup currently blocked threads.
for (cur = (mvm::Thread*)self->next(); cur != self;
cur = (mvm::Thread*)cur->next()) {
More information about the vmkit-commits
mailing list