--- a/src/JavaMonitor.st Wed Nov 30 14:15:44 2011 +0000
+++ b/src/JavaMonitor.st Wed Nov 30 19:52:16 2011 +0000
@@ -22,7 +22,7 @@
Object subclass:#JavaMonitor
instanceVariableNames:'owningProcess processesEntered monitorSema count waitingSema
- processesWaiting'
+ processesWaiting waitEnabled owner'
classVariableNames:'instVarAccess'
poolDictionaries:''
category:'Languages-Java-Support'
@@ -64,10 +64,10 @@
!JavaMonitor class methodsFor:'instance creation'!
-new
-^self basicNew initialize.
+for: owningObject
+ ^ self basicNew initializeFor: owningObject.
- "Created: / 20-11-2011 / 14:30:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Created: / 30-11-2011 / 20:39:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !
!JavaMonitor methodsFor:'accessing'!
@@ -112,6 +112,18 @@
"Created: / 22-11-2011 / 10:49:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
!
+disableWait
+ instVarAccess critical: [ waitEnabled := false ].
+
+ "Created: / 30-11-2011 / 20:34:40 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+enableWait
+instVarAccess critical: [waitEnabled := true].
+
+ "Created: / 30-11-2011 / 20:34:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
increment
"owning process entered monitor again (recursion ...), lets raise our counter so we know how many times
do we have to release it"
@@ -170,22 +182,37 @@
].
"Created: / 20-11-2011 / 20:28:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+waitEnabled
+ instVarAccess critical: [ ^ waitEnabled].
+
+ "Created: / 30-11-2011 / 20:34:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !
!JavaMonitor methodsFor:'initialization'!
initialize
owningProcess := nil.
-
processesEntered := OrderedCollection new.
-
monitorSema := Semaphore new: 1.
-
processesWaiting := Dictionary new.
-
waitingSema := Semaphore new: 0.
+ waitEnabled.
"Created: / 20-11-2011 / 13:28:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+!
+
+initializeFor: owningObject
+ owningProcess := nil.
+ processesEntered := OrderedCollection new.
+ monitorSema := Semaphore new: 1.
+ processesWaiting := Dictionary new.
+ waitingSema := Semaphore new: 0.
+ waitEnabled := true.
+ owner := owningObject.
+
+ "Created: / 30-11-2011 / 20:39:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !
!JavaMonitor methodsFor:'public'!
@@ -287,8 +314,11 @@
| thisProcess |
thisProcess := Processor activeProcess.
self assert: (self isOwnedBy: thisProcess).
+ self waitEnabled ifFalse: [Logger log:( '%1 wanted to go to sleep, but it cant, this monitor is for %2 which is already dead' bindWith: thisProcess printString with: owner printString) severity: #debug facility:#JVM. ^self.].
Logger
- log: ('%1 is going to wait for timeout: %2' bindWith: thisProcess printString with: timeOut)
+ log: ('%1 is going to wait for timeout: %2'
+ bindWith: thisProcess printString
+ with: timeOut)
severity: #debug
facility: #JVM.
self processesWaitingAdd: thisProcess.
@@ -307,7 +337,7 @@
"Created: / 22-11-2011 / 12:52:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
"Modified (comment): / 25-11-2011 / 18:30:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
- "Modified: / 29-11-2011 / 16:02:01 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
+ "Modified: / 30-11-2011 / 20:38:39 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
! !
!JavaMonitor methodsFor:'queries'!