[PATCH] #returnFromSnapshot tweaks

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] #returnFromSnapshot tweaks

Paolo Bonzini-2
This includes two tweaks that are necessary to be able to restore the
demo.st Cairo demo from a saved image.  First, #returnFromSnapshot
callbacks should run at a high priority.  Because it reloads shared
libraries and modules, a concurrent process might start using the shared
library before it's been loaded.  With the heavy usage of Delay in the
SDL demos, this was routinely happening.  However, this does not protect
against other #returnFromSnapshot callbacks.  To do so, I hacked a
little and run the DLD callback separately, rather than with
Object>>#changed:.

Another point, not covered by the patch, is that it is not necessary to
call SDL_VideoQuit.  Doing so actually can cause dangling pointers all
over the place. :-)

Paolo

2008-04-17  Paolo Bonzini  <[hidden email]>

        * kernel/DLD.st: Don't register DLD with ObjectMemory.
        * kernel/ObjMemory.st: Execute #returnFromSnapshot callback
        at high priority, and pass it to DLD before anything else.

diff --git a/NEWS b/NEWS
index 78e33aa..104d732 100644
--- a/NEWS
+++ b/NEWS
@@ -59,6 +59,9 @@ o   The semantics of #on:do: were changed: executing off the end of an
     Older versions of GNU Smalltalk either returned or resumed depending
     on the resumability of the exception.
 
+o   The callback for the #returnFromSnapshot event is executed as a
+    high-priority process.  Remember this!
+
 o   New tool gst-remote allows remote control of a GNU Smalltalk VM
     via a TCP socket.
 
diff --git a/kernel/DLD.st b/kernel/DLD.st
index 9533412..b5c50ca 100644
--- a/kernel/DLD.st
+++ b/kernel/DLD.st
@@ -227,7 +227,6 @@ in CFunctionDescriptor.'>
  libraryList := OrderedCollection new.
  libraryStream := Kernel.RoundRobinStream on: libraryList readStream.
  moduleList := OrderedCollection new.
- ObjectMemory addDependent: DLD
     ]
 
     DLD class >> update: aspect [
diff --git a/kernel/ObjMemory.st b/kernel/ObjMemory.st
index d2b0742..15a6b47 100644
--- a/kernel/ObjMemory.st
+++ b/kernel/ObjMemory.st
@@ -47,14 +47,29 @@ class-side method to take a look at statistics on the memory manager''s
 state.'>
 
     ObjectMemory class >> changed: aSymbol [
- "Before quitting, wait until all processes are done."
  <category: 'initialization'>
- aSymbol == #aboutToQuit
-    ifTrue:
- [
- Processor activeProcess priority: Processor rockBottomPriority.
- [super changed: aSymbol] forkAt: Processor userSchedulingPriority]
-    ifFalse: [super changed: aSymbol]
+ | sema prio |
+ prio := aSymbol == #returnFromSnapshot
+    ifTrue: [Processor highIOPriority]
+    ifFalse: [Processor userSchedulingPriority].
+
+ Processor activePriority < prio
+    ifTrue: [
+ sema := Semaphore new.
+
+ "Ensure that modules and libraries are initialized before
+ anything else happens."
+ [DLD update: aSymbol. super changed: aSymbol.
+ sema signal]
+    forkAt: prio.
+ sema wait]
+    ifFalse: [
+ DLD update: aSymbol. super changed: aSymbol].
+
+ "Before quitting, wait until all processes are done."
+ aSymbol == #aboutToQuit ifTrue: [
+    Processor activeProcess priority: Processor rockBottomPriority.
+    Processor yield].
     ]
 
     ObjectMemory class >> initialize [

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk