Fixed SmallSense::Manager class>>flush
authorJan Vrany <jan.vrany@fit.cvut.cz>
Fri, 21 Nov 2014 17:46:35 +0000
changeset 303 ae129236a9ec
parent 302 44433b666576
child 305 0245502aa9f9
Fixed SmallSense::Manager class>>flush flush should first release old manager instance, i.e., break dependencies and stop inferencing process in case it's working.
SmallSense__Manager.st
--- a/SmallSense__Manager.st	Fri Nov 21 17:31:26 2014 +0000
+++ b/SmallSense__Manager.st	Fri Nov 21 17:46:35 2014 +0000
@@ -21,7 +21,7 @@
 "{ NameSpace: SmallSense }"
 
 Object subclass:#Manager
-	instanceVariableNames:'classes accessLock updater seqno'
+	instanceVariableNames:'classes accessLock updater updaterThread seqno'
 	classVariableNames:'Instance'
 	poolDictionaries:''
 	category:'SmallSense-Smalltalk-Types-Info'
@@ -55,23 +55,29 @@
 flush
     "flushes the cached singleton"
 
-    Instance := nil
+    self flushSingleton
 
     "
      self flushSingleton
     "
 
     "Created: / 16-12-2011 / 01:37:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-11-2014 / 17:34:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 flushSingleton
     "flushes the cached singleton"
 
+    Instance notNil ifTrue:[ 
+        Instance release.
+    ].
     Instance := nil
 
     "
      self flushSingleton
     "
+
+    "Modified: / 21-11-2014 / 17:34:53 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 instance
@@ -177,6 +183,20 @@
     seqno := 0
 
     "Modified: / 22-10-2013 / 10:56:51 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+release
+    "Invoked when a new instance is created."
+
+    classes := nil.
+    accessLock := Semaphore forMutualExclusion.
+    updater stopAndRemoveAll.
+
+    UserPreferences current smallSenseEnabled ifTrue:[
+        Smalltalk removeDependent: self.
+    ].
+
+    "Created: / 21-11-2014 / 17:36:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !Manager methodsFor:'updating'!
@@ -264,6 +284,16 @@
 !
 
 delayedUpdateInfoForClassOrMethod: classOrMethod
+    | currentThread |
+
+    currentThread := Processor activeProcess.
+    updaterThread ~~ currentThread ifTrue:[ 
+        updaterThread := currentThread.
+        updaterThread addExitAction:[ 
+            updater stopAndRemoveAll.
+        ].
+    ].
+
     [
         classOrMethod isBehavior ifTrue:[
            self delayedUpdateInfoForClass: classOrMethod.
@@ -276,7 +306,7 @@
     ]
 
     "Created: / 27-11-2011 / 18:01:07 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 21-11-2014 / 16:20:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 21-11-2014 / 17:39:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 delayedUpdateInfoForMethod: method