[vmkit-commits] [vmkit] r121264 - in /vmkit/branches/multi-vm: include/mvm/VirtualMachine.h lib/Mvm/Runtime/VirtualMachine.cpp
Gael Thomas
gael.thomas at lip6.fr
Wed Dec 8 08:43:41 PST 2010
Author: gthomas
Date: Wed Dec 8 10:43:41 2010
New Revision: 121264
URL: http://llvm.org/viewvc/llvm-project?rev=121264&view=rev
Log:
Add functions to start the vm in a vmkit non deamon thread. Not used for the moment.
Modified:
vmkit/branches/multi-vm/include/mvm/VirtualMachine.h
vmkit/branches/multi-vm/lib/Mvm/Runtime/VirtualMachine.cpp
Modified: vmkit/branches/multi-vm/include/mvm/VirtualMachine.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/include/mvm/VirtualMachine.h?rev=121264&r1=121263&r2=121264&view=diff
==============================================================================
--- vmkit/branches/multi-vm/include/mvm/VirtualMachine.h (original)
+++ vmkit/branches/multi-vm/include/mvm/VirtualMachine.h Wed Dec 8 10:43:41 2010
@@ -50,7 +50,45 @@
//===----------------------------------------------------------------------===//
/// buildVMThreadData - allocate a java thread for the underlying mutator. Called when the java thread is a foreign thread.
///
- virtual VMThreadData* buildVMThreadData(Thread* mut) { return new VMThreadData(this, mut); }
+ virtual VMThreadData* buildVMThreadData(Thread* mut) = 0; //{ return new VMThreadData(this, mut); }
+
+ /// nbNonDaemonThreads - Number of threads in the system that are not daemon
+ /// threads.
+ uint16 nbNonDaemonThreads;
+
+ /// nonDaemonLock - Protection lock for the nonDaemonThreads variable.
+ mvm::LockNormal nonDaemonLock;
+
+ /// nonDaemonVar - Condition variable to wake up the initial thread when it
+ /// waits for other non-daemon threads to end. The non-daemon thread that
+ /// decrements the nonDaemonThreads variable to zero wakes up the initial
+ /// thread.
+ mvm::Cond nonDaemonVar;
+
+ /// enter - A thread calls this function when it enters the thread system.
+ virtual void enterNonDeamonMode();
+
+ /// leave - A thread calls this function when it leaves the thread system.
+ virtual void leaveNonDeamonMode();
+
+ virtual void runApplicationImpl(int argc, char** argv) {};
+
+ /// runInNonDeamonThread - start a non deamon thread a begin the code with start if != 0 and runApplicationImpl otherwise
+ /// the thread leaves the deamon mode when it finishs.
+ void runInNonDeamonThread(void (*start)(VirtualMachine*, int, char**), int argc, char** argv);
+
+ /// runInNonDeamonThread - start a non deamon thread a begin the code with runApplicationImpl,
+ void runInNonDeamonThread(int argc, char **argv) { runInNonDeamonThread(0, argc, argv); }
+
+ /// waitNonDeamonThreads - wait until all the non deamon threads are terminated.
+ void waitForNonDeamonThreads();
+
+ /// runApplication - Run an application. The application name is in
+ /// the arguments, hence it is the virtual machine's job to parse them.
+ virtual void runApplication(int argc, char** argv) = 0;
+
+ /// waitForExit - Wait until the virtual machine stops its execution.
+ virtual void waitForExit() = 0;
//===----------------------------------------------------------------------===//
// (2) GC-related methods.
@@ -96,13 +134,6 @@
//===----------------------------------------------------------------------===//
// (4) Launch-related methods.
//===----------------------------------------------------------------------===//
-
- /// runApplication - Run an application. The application name is in
- /// the arguments, hence it is the virtual machine's job to parse them.
- virtual void runApplication(int argc, char** argv) = 0;
-
- /// waitForExit - Wait until the virtual machine stops its execution.
- virtual void waitForExit() = 0;
};
} // end namespace mvm
Modified: vmkit/branches/multi-vm/lib/Mvm/Runtime/VirtualMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/branches/multi-vm/lib/Mvm/Runtime/VirtualMachine.cpp?rev=121264&r1=121263&r2=121264&view=diff
==============================================================================
--- vmkit/branches/multi-vm/lib/Mvm/Runtime/VirtualMachine.cpp (original)
+++ vmkit/branches/multi-vm/lib/Mvm/Runtime/VirtualMachine.cpp Wed Dec 8 10:43:41 2010
@@ -11,3 +11,54 @@
VirtualMachine::~VirtualMachine() {
vmkit->removeVM(vmID);
}
+
+void VirtualMachine::leaveNonDeamonMode() {
+ nonDaemonLock.lock();
+ --nbNonDaemonThreads;
+ if (nbNonDaemonThreads == 0) nonDaemonVar.signal();
+ nonDaemonLock.unlock();
+}
+
+void VirtualMachine::enterNonDeamonMode() {
+ nonDaemonLock.lock();
+ ++nbNonDaemonThreads;
+ nonDaemonLock.unlock();
+}
+
+void VirtualMachine::waitForNonDeamonThreads() {
+ nonDaemonLock.lock();
+
+ while (nbNonDaemonThreads) {
+ nonDaemonVar.wait(&nonDaemonLock);
+ }
+
+ nonDaemonLock.unlock();
+}
+
+class LauncherThread : public Thread {
+public:
+ void (*realStart)(VirtualMachine*, int, char**);
+ VirtualMachine *vm;
+ int argc;
+ char** argv;
+
+ LauncherThread(VMKit* vmkit, void (*s)(VirtualMachine*, int, char**), VirtualMachine* v, int ac, char** av) : Thread(vmkit) {
+ realStart = s;
+ vm = v;
+ argc = ac;
+ argv = av;
+ }
+
+ static void launch(LauncherThread* th) {
+ if(th->realStart)
+ th->realStart(th->vm, th->argc, th->argv);
+ else
+ th->vm->runApplicationImpl(th->argc, th->argv);
+ th->vm->leaveNonDeamonMode();
+ }
+};
+
+void VirtualMachine::runInNonDeamonThread(void (*start)(VirtualMachine*, int, char**), int argc, char **argv) {
+ enterNonDeamonMode();
+ (new LauncherThread(vmkit, start, this, argc, argv))->start((void (*)(Thread*))LauncherThread::launch);
+}
More information about the vmkit-commits
mailing list