[vmkit-commits] [vmkit] r120940 - in /vmkit/branches/multi-vm: include/mvm/Threads/Thread.h include/mvm/VMKit.h lib/Mvm/CommonThread/ctthread.cpp lib/Mvm/Runtime/VMKit.cpp
Gael Thomas
gael.thomas at lip6.fr
Sun Dec 5 07:33:19 PST 2010
Author: gthomas
Date: Sun Dec 5 09:33:19 2010
New Revision: 120940
URL: http://llvm.org/viewvc/llvm-project?rev=120940&view=rev
Log:
add a new state for threads: prepared. When a thread is prepared, vmkit realloc its allVmsData but it does not consider it for rendezvous
Modified:
vmkit/branches/multi-vm/include/mvm/Threads/Thread.h
vmkit/branches/multi-vm/include/mvm/VMKit.h
vmkit/branches/multi-vm/lib/Mvm/CommonThread/ctthread.cpp
vmkit/branches/multi-vm/lib/Mvm/Runtime/VMKit.cpp
Modified: vmkit/branches/multi-vm/include/mvm/Threads/Thread.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/include/mvm/Threads/Thread.h?rev=120940&r1=120939&r2=120940&view=diff
==============================================================================
--- vmkit/branches/multi-vm/include/mvm/Threads/Thread.h (original)
+++ vmkit/branches/multi-vm/include/mvm/Threads/Thread.h Sun Dec 5 09:33:19 2010
@@ -157,18 +157,11 @@
/// contains all thread-specific informations.
// WARNING: if you modify this class, you must also change mvm-runtime.ll
class Thread : public CircularBase<Thread> {
+protected:
+ Thread(VMKit* vmk);
+
public:
- Thread(VMKit* vmk) {
-#ifdef RUNTIME_DWARF_EXCEPTIONS
- internalPendingException = 0;
-#else
- lastExceptionBuffer = 0;
-#endif
- _vmkit = vmk;
- lastKnownFrame = 0;
- pendingException = 0;
- allVmsData = 0;
- }
+ ~Thread();
/// yield - Yield the processor to another thread.
///
Modified: vmkit/branches/multi-vm/include/mvm/VMKit.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/include/mvm/VMKit.h?rev=120940&r1=120939&r2=120940&view=diff
==============================================================================
--- vmkit/branches/multi-vm/include/mvm/VMKit.h (original)
+++ vmkit/branches/multi-vm/include/mvm/VMKit.h Sun Dec 5 09:33:19 2010
@@ -60,6 +60,10 @@
/// ------------------------------------------------- ///
/// --- thread managment --- ///
/// ------------------------------------------------- ///
+ /// preparedThreads - the list of prepared threads, they are not yet running.
+ ///
+ CircularBase<Thread> preparedThreads;
+
/// runningThreads - the list of running threads
///
CircularBase<Thread> runningThreads;
@@ -75,8 +79,11 @@
UncooperativeCollectionRV rendezvous;
#endif
- void addThread(mvm::Thread* th);
- void removeThread(mvm::Thread* th);
+ void registerPreparedThread(mvm::Thread* th);
+ void unregisterPreparedThread(mvm::Thread* th);
+
+ void registerRunningThread(mvm::Thread* th);
+ void unregisterRunningThread(mvm::Thread* th);
/// ------------------------------------------------- ///
/// --- backtrace related methods --- ///
Modified: vmkit/branches/multi-vm/lib/Mvm/CommonThread/ctthread.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/lib/Mvm/CommonThread/ctthread.cpp?rev=120940&r1=120939&r2=120940&view=diff
==============================================================================
--- vmkit/branches/multi-vm/lib/Mvm/CommonThread/ctthread.cpp (original)
+++ vmkit/branches/multi-vm/lib/Mvm/CommonThread/ctthread.cpp Sun Dec 5 09:33:19 2010
@@ -31,6 +31,23 @@
using namespace mvm;
+Thread::Thread(VMKit* vmk) {
+#ifdef RUNTIME_DWARF_EXCEPTIONS
+ internalPendingException = 0;
+#else
+ lastExceptionBuffer = 0;
+#endif
+ _vmkit = vmk;
+ lastKnownFrame = 0;
+ pendingException = 0;
+ allVmsData = 0;
+ vmk->registerPreparedThread(this);
+}
+
+Thread::~Thread() {
+ vmkit()->unregisterPreparedThread(this);
+}
+
// must be protected by rendezvous.threadLock
void Thread::reallocAllVmsData(int old, int n) {
VMThreadData **newData = new VMThreadData*[n];
@@ -447,7 +464,7 @@
#endif
th->vmkit()->rendezvous.prepareForJoin();
th->routine(th);
- th->vmkit()->removeThread(th);
+ th->vmkit()->unregisterRunningThread(th);
}
@@ -462,7 +479,7 @@
routine = fct;
// Make sure to add it in the list of threads before leaving this function:
// the garbage collector wants to trace this thread.
- vmkit()->addThread(this);
+ vmkit()->registerRunningThread(this);
int res = pthread_create((pthread_t*)(void*)(&internalThreadID), &attributs,
(void* (*)(void *))internalThreadStart, this);
pthread_detach((pthread_t)internalThreadID);
Modified: vmkit/branches/multi-vm/lib/Mvm/Runtime/VMKit.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/lib/Mvm/Runtime/VMKit.cpp?rev=120940&r1=120939&r2=120940&view=diff
==============================================================================
--- vmkit/branches/multi-vm/lib/Mvm/Runtime/VMKit.cpp (original)
+++ vmkit/branches/multi-vm/lib/Mvm/Runtime/VMKit.cpp Sun Dec 5 09:33:19 2010
@@ -28,6 +28,10 @@
delete[] oldVms;
// reallocate the allVMDatas
+ for(Thread* cur=preparedThreads.next(); cur!=&preparedThreads; cur=cur->next()) {
+ cur->reallocAllVmsData(res, numberOfVms);
+ }
+
for(Thread* cur=runningThreads.next(); cur!=&runningThreads; cur=cur->next()) {
cur->reallocAllVmsData(res, numberOfVms);
}
@@ -38,21 +42,37 @@
}
void VMKit::removeVM(size_t id) {
+ // what can I do with the VMThreadData?
vms[id] = 0;
}
-void VMKit::addThread(mvm::Thread* th) {
+void VMKit::registerPreparedThread(mvm::Thread* th) {
+ vmkitLock.lock();
+ th->appendTo(&preparedThreads);
+ th->reallocAllVmsData(0, numberOfVms);
+ vmkitLock.unlock();
+}
+
+void VMKit::unregisterPreparedThread(mvm::Thread* th) {
+ vmkitLock.lock();
+ numberOfRunningThreads--;
+ th->remove();
+ delete th->allVmsData;
+ vmkitLock.unlock();
+}
+
+void VMKit::registerRunningThread(mvm::Thread* th) {
vmkitLock.lock();
numberOfRunningThreads++;
+ th->remove();
th->appendTo(&runningThreads);
- th->reallocAllVmsData(0, numberOfVms);
vmkitLock.unlock();
}
-void VMKit::removeThread(mvm::Thread* th) {
+void VMKit::unregisterRunningThread(mvm::Thread* th) {
vmkitLock.lock();
numberOfRunningThreads--;
th->remove();
- th->allVmsData = 0;
+ th->appendTo(&preparedThreads);
vmkitLock.unlock();
}
More information about the vmkit-commits
mailing list