[vmkit-commits] [vmkit] r85563 - in /vmkit/trunk: include/mvm/Threads/CollectionRV.h lib/Mvm/CommonThread/CollectionRV.cpp
Nicolas Geoffray
nicolas.geoffray at lip6.fr
Thu Oct 29 18:45:24 PDT 2009
Author: geoffray
Date: Thu Oct 29 20:45:24 2009
New Revision: 85563
URL: http://llvm.org/viewvc/llvm-project?rev=85563&view=rev
Log:
Race fixes for rendezvous.
Modified:
vmkit/trunk/include/mvm/Threads/CollectionRV.h
vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp
Modified: vmkit/trunk/include/mvm/Threads/CollectionRV.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/mvm/Threads/CollectionRV.h?rev=85563&r1=85562&r2=85563&view=diff
==============================================================================
--- vmkit/trunk/include/mvm/Threads/CollectionRV.h (original)
+++ vmkit/trunk/include/mvm/Threads/CollectionRV.h Thu Oct 29 20:45:24 2009
@@ -90,9 +90,9 @@
void synchronize();
- void addForeignThread(mvm::Thread* th);
-
void join();
+
+ unsigned getNumber() { return rendezvousNb; }
};
}
Modified: vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp?rev=85563&r1=85562&r2=85563&view=diff
==============================================================================
--- vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp (original)
+++ vmkit/trunk/lib/Mvm/CommonThread/CollectionRV.cpp Thu Oct 29 20:45:24 2009
@@ -24,13 +24,13 @@
}
void CollectionRV::waitRV() {
- mvm::Thread* self = mvm::Thread::get();
- lockRV();
-
+ mvm::Thread* self = mvm::Thread::get();
+ // Add myself.
+ another_mark();
+
while (nbJoined < self->MyVM->NumberOfThreads)
condInitiator.wait(&_lockRV);
- unlockRV();
}
void CollectionRV::synchronize() {
@@ -57,26 +57,21 @@
cur->doYield = true;
cur = (mvm::Thread*)cur->next();
} while (cur != self);
-
- // Unlock now. Each running thread will join the rendezvous.
- unlockRV();
-
+
// Lookup currently blocked threads.
- for (mvm::Thread* cur = (mvm::Thread*)self->next(); cur != self;
+ for (cur = (mvm::Thread*)self->next(); cur != self;
cur = (mvm::Thread*)cur->next()) {
- void* val = cur->getLastSP();
- // If val is null, this means that the thread woke up, and is
- // joining the rendezvous. We are sure the thread will join the
- // rendezvous.
- if (val) addForeignThread(cur);
+ if (cur->getLastSP()) {
+ another_mark();
+ cur->joinedRV = true;
+ }
}
-
- // Add myself.
- another_mark();
-
+
// And wait for other threads to join.
waitRV();
+ unlockRV();
+
} else {
mvm::Thread* self = mvm::Thread::get();
self->joinedRV = false;
@@ -90,11 +85,10 @@
cur->killForRendezvous();
}
- // Add myself.
- another_mark();
-
+ lockRV();
// And wait for other threads to finish.
waitRV();
+ unlockRV();
}
self->MyVM->ThreadLock.unlock();
@@ -125,26 +119,18 @@
}
}
+ assert(th->getLastSP() && "Joined without giving a SP");
// Wait for the rendezvous to finish.
waitEndOfRV();
- unlockRV();
// The rendezvous is finished. Set inRV to false.
th->inRV = false;
if (changed) th->setLastSP(0);
-}
-
-void CollectionRV::addForeignThread(mvm::Thread* th) {
- lockRV();
-
- // The thread may have waken up during this GC. In this case, it may have
- // put itself into the waiting list.
- if (!th->joinedRV) {
- another_mark();
- th->joinedRV = true;
- }
-
+
+ // Unlock after modifying lastSP, because lastSP is also read by the
+ // rendezvous initiator.
unlockRV();
+
}
extern "C" void conditionalSafePoint() {
More information about the vmkit-commits
mailing list