[vmkit-commits] [vmkit] r180502 - Implementing addShutdownHook

Peter Senna Tschudin peter.senna at gmail.com
Thu Apr 25 10:18:40 PDT 2013


Author: peter.senna
Date: Thu Apr 25 12:17:10 2013
New Revision: 180502

URL: http://llvm.org/viewvc/llvm-project?rev=180502&view=rev
Log:
Implementing addShutdownHook
(cherry picked from commit 46f715401dcec61d23a2f21c76471ee13811b54f)

Modified:
    vmkit/trunk/include/vmkit/Locks.h
    vmkit/trunk/lib/vmkit/CommonThread/Sigsegv.cpp
    vmkit/trunk/lib/vmkit/CommonThread/ctlock.cpp

Modified: vmkit/trunk/include/vmkit/Locks.h
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/include/vmkit/Locks.h?rev=180502&r1=180501&r2=180502&view=diff
==============================================================================
--- vmkit/trunk/include/vmkit/Locks.h (original)
+++ vmkit/trunk/include/vmkit/Locks.h Thu Apr 25 12:17:10 2013
@@ -29,6 +29,10 @@ class LockNormal;
 class LockRecursive;
 class Thread;
 
+extern LockNormal lockForCtrl_C;
+extern Cond condForCtrl_C;
+extern bool finishForCtrl_C;
+
 /// Lock - This class is an abstract class for declaring recursive and normal
 /// locks.
 ///
@@ -93,6 +97,7 @@ public:
 
   virtual void lock() __attribute__ ((noinline));
   virtual void unlock(vmkit::Thread* ownerThread = NULL);
+  int tryLock();
 
 };
 

Modified: vmkit/trunk/lib/vmkit/CommonThread/Sigsegv.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/vmkit/CommonThread/Sigsegv.cpp?rev=180502&r1=180501&r2=180502&view=diff
==============================================================================
--- vmkit/trunk/lib/vmkit/CommonThread/Sigsegv.cpp (original)
+++ vmkit/trunk/lib/vmkit/CommonThread/Sigsegv.cpp Thu Apr 25 12:17:10 2013
@@ -12,6 +12,7 @@
 #include "vmkit/System.h"
 #include "vmkit/VirtualMachine.h"
 #include "vmkit/Thread.h"
+#include "vmkit/Locks.h"
 
 #include <csignal>
 #include <cstdio>
@@ -97,7 +98,11 @@ void sigsegvHandler(int n, siginfo_t *in
 
 void sigsTermHandler(int n, siginfo_t *info, void *context) {
 	fprintf(stderr, "\nJVM termination because user request\n");
-	Thread::get()->onVMTermination();
+	finishForCtrl_C = true;
+	condForCtrl_C.signal();
+	//lockForCtrl_C.Lock();
+	//lockForCtrl_C.unlock()
+	//Thread::get()->onVMTermination();
 	//UserClass* cl = vm->upcalls->SystemClass;
 	//vm -> upcalls->SystemExit->invokeIntStatic(vm,Class* cl, 0);
 }

Modified: vmkit/trunk/lib/vmkit/CommonThread/ctlock.cpp
URL: http://llvm.org/viewvc/llvm-project/vmkit/trunk/lib/vmkit/CommonThread/ctlock.cpp?rev=180502&r1=180501&r2=180502&view=diff
==============================================================================
--- vmkit/trunk/lib/vmkit/CommonThread/ctlock.cpp (original)
+++ vmkit/trunk/lib/vmkit/CommonThread/ctlock.cpp Thu Apr 25 12:17:10 2013
@@ -21,6 +21,15 @@
 
 namespace vmkit {
 
+/**
+ * These variables are used to implement some behavior
+ * when the user presses Ctrl_C.
+ */
+LockNormal lockForCtrl_C;
+Cond condForCtrl_C;
+bool finishForCtrl_C = false;
+
+
 Lock::Lock() {
   pthread_mutexattr_t attr;
 
@@ -72,6 +81,17 @@ void LockNormal::lock() {
   owner = th;
 }
 
+int LockNormal::tryLock() {
+  Thread* th = Thread::get();
+  th->enterUncooperativeCode();
+  //pthread_mutex_lock((pthread_mutex_t*)&internalLock);
+  int r = pthread_mutex_trylock((pthread_mutex_t*)&internalLock);
+  th->leaveUncooperativeCode();
+  if (r == 0)
+	  owner = th;
+  return r;
+}
+
 void LockNormal::unlock(vmkit::Thread* ownerThread) {
   assert(selfOwner(ownerThread) && "Not owner when unlocking");
   owner = 0;
@@ -191,10 +211,10 @@ int Cond::timedWait(Lock* l, struct time
                                    &timeout);
   th->leaveUncooperativeCode();
   
-//  if (res != 0) {
-//  		pthread_cond_destroy (&internalCond) ;
-//  		pthread_cond_init    (&internalCond, NULL);
-//  }
+  if (res != 0) {
+  		pthread_cond_destroy (&internalCond) ;
+  		pthread_cond_init    (&internalCond, NULL);
+  }
 
   assert((!res || res == ETIMEDOUT) && "Error on timed wait");
   l->unsafeLock(n);
@@ -229,7 +249,7 @@ int Cond::myTimeWait(Lock* l, bool isAbs
 		  absTime.tv_nsec = 0;
 		}
 		else {
-		  absTime.tv_sec = now.tv_sec + secs + 1100; // 150 / 850 / 1000
+		  absTime.tv_sec = now.tv_sec + secs + 0; // 150 / 850 / 1000
 		  absTime.tv_nsec = (nsec % NANOSECS_PER_SEC) + now.tv_usec*1000;
 		  if (absTime.tv_nsec >= NANOSECS_PER_SEC) {
 			absTime.tv_nsec -= NANOSECS_PER_SEC;
@@ -248,10 +268,10 @@ int Cond::myTimeWait(Lock* l, bool isAbs
 								   &absTime);
 	th->leaveUncooperativeCode();
 
-	//if (res != 0) {
-	//	pthread_cond_destroy (&internalCond) ;
-	//	pthread_cond_init    (&internalCond, NULL);
-	//}
+	if (res != 0) {
+		pthread_cond_destroy (&internalCond) ;
+		pthread_cond_init    (&internalCond, NULL);
+	}
 
 	assert((!res || res == ETIMEDOUT) && "Error on timed wait");
 	l->unsafeLock(n);





More information about the vmkit-commits mailing list