JavaObject.st
changeset 3767 13867af21c6a
parent 3551 f8304e321df7
child 3782 32e335ed7c6f
--- a/JavaObject.st	Tue Sep 20 22:56:52 2016 +0100
+++ b/JavaObject.st	Wed Oct 12 00:14:35 2016 +0100
@@ -535,6 +535,66 @@
     "Modified: 22.3.1997 / 00:56:54 / cg"
 ! !
 
+!JavaObject methodsFor:'synchronized evaluation'!
+
+freeSynchronizationSemaphore
+    "free synchronizationSemaphore. May be used, to save memory when
+     an object is no longer used synchronized."
+
+    ^ self shouldNotImplement
+
+    "
+     self synchronized:[].
+     self synchronizationSemaphore.
+     self freeSynchronizationSemaphore.
+    "
+
+    "Created: / 28-01-1997 / 19:31:20 / stefan"
+    "Modified: / 08-12-2013 / 22:21:01 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+synchronizationSemaphore
+    "return the synchronization semaphore for myself.
+     subclasses may redefine"
+
+    ^ self shouldNotImplement
+
+    "
+      self synchronizationSemaphore
+    "
+
+    "Modified: / 28-01-1997 / 19:47:09 / stefan"
+    "Modified: / 08-12-2013 / 22:21:08 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+synchronizationSemaphore:aSemaphore
+    "set the synchronisationSemaphore for myself.
+     subclasses may redefine this method"
+
+    ^ self shouldNotImplement
+
+    "Modified: / 28-01-1997 / 19:37:48 / stefan"
+    "Modified: / 08-12-2013 / 22:21:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+synchronized:aBlock
+    "Evaluate aBlock synchronized, i.e. use a monitor for this object"
+
+%{
+    extern void __monitorEnter(OBJ obj);
+    __monitorEnter(self);
+%}.
+    aBlock ensure:[
+%{
+    extern void __monitorExit(OBJ obj);
+    __monitorExit(self);
+%}.
+    1. "/ To make stc happy (stc needs a return value but primitive code has none)
+    ].
+
+    "Modified: / 11-10-2016 / 23:40:57 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+! !
+
 !JavaObject methodsFor:'unwind'!
 
 unwindHandlerInContext: aContext