src/JavaMonitor.st
author hlopkmar
Tue, 28 Aug 2012 16:06:54 +0000
branchjk_new_structure
changeset 1689 5da8961dff01
parent 1490 098c357e3c2f
child 1690 2dbce03c979a
permissions -rw-r--r--
- JavaMonitor class definition changed: #initialize #initializeFor:thread:nestedLockCount: - extensions ...
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
     1
"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
     2
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1148
diff changeset
     3
1155
vranyj1
parents: 1152
diff changeset
     4
 New code and modifications done at SWING Research Group [1]:
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1148
diff changeset
     5
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
     6
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
     7
                            SWING Research Group, Czech Technical University in Prague
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
     8
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
     9
 This software is furnished under a license and may be used
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    10
 only in accordance with the terms of that license and with the
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    11
 inclusion of the above copyright notice.   This software may not
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    12
 be provided or otherwise made available to, or used by, any
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    13
 other person.  No title to or ownership of the software is
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    14
 hereby transferred.
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    15
1155
vranyj1
parents: 1152
diff changeset
    16
 [1] Code written at SWING Research Group contains a signature
vranyj1
parents: 1152
diff changeset
    17
     of one of the above copright owners. For exact set of such code,
vranyj1
parents: 1152
diff changeset
    18
     see the differences between this version and version stx:libjava
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1148
diff changeset
    19
     as of 1.9.2010
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    20
"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    21
"{ Package: 'stx:libjava' }"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    22
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    23
Object subclass:#JavaMonitor
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
    24
	instanceVariableNames:'owningProcess processesEntered monitorSema count waitingSema
1689
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
    25
		processesWaiting waitEnabled ownerPrintString instVarAccess'
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
    26
	classVariableNames:''
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    27
	poolDictionaries:''
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    28
	category:'Languages-Java-Support'
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    29
!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    30
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    31
!JavaMonitor class methodsFor:'documentation'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    32
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    33
copyright
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    34
"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    35
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1148
diff changeset
    36
1155
vranyj1
parents: 1152
diff changeset
    37
 New code and modifications done at SWING Research Group [1]:
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1148
diff changeset
    38
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    39
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    40
                            SWING Research Group, Czech Technical University in Prague
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    41
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    42
 This software is furnished under a license and may be used
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    43
 only in accordance with the terms of that license and with the
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    44
 inclusion of the above copyright notice.   This software may not
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    45
 be provided or otherwise made available to, or used by, any
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    46
 other person.  No title to or ownership of the software is
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    47
 hereby transferred.
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    48
1155
vranyj1
parents: 1152
diff changeset
    49
 [1] Code written at SWING Research Group contains a signature
vranyj1
parents: 1152
diff changeset
    50
     of one of the above copright owners. For exact set of such code,
vranyj1
parents: 1152
diff changeset
    51
     see the differences between this version and version stx:libjava
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1148
diff changeset
    52
     as of 1.9.2010
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    53
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    54
"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    55
! !
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    56
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
    57
!JavaMonitor class methodsFor:'initialization'!
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
    58
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
    59
initialize
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
    60
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
    61
    "Created: / 29-11-2011 / 11:23:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1689
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
    62
    "Modified: / 28-08-2012 / 18:01:33 / m"
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
    63
! !
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
    64
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    65
!JavaMonitor class methodsFor:'instance creation'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    66
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
    67
for: owningObject
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
    68
    ^ self basicNew initializeFor: owningObject.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    69
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
    70
    "Created: / 30-11-2011 / 20:39:55 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1689
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
    71
!
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
    72
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
    73
for: owningObject thread: threadOrNil nestedLockCount: count
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
    74
    ^ self basicNew initializeFor: owningObject thread: threadOrNil nestedLockCount: count
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
    75
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
    76
    "Created: / 26-08-2012 / 17:01:43 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    77
! !
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    78
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    79
!JavaMonitor methodsFor:'accessing'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    80
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    81
activeProcess
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    82
    ^ Processor activeProcess
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    83
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    84
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    85
copyProcessesEntered
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    86
    ^ processesEntered copy.
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    87
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    88
    "Created: / 20-11-2011 / 14:45:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    89
!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    90
1689
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
    91
count
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
    92
    ^ count
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
    93
!
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
    94
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    95
processesEntered
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    96
    "dont do anything to me, access needs to be sync'd"
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    97
    ^ processesEntered.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    98
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    99
    "Created: / 20-11-2011 / 13:22:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   100
! !
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   101
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   102
!JavaMonitor methodsFor:'atomic'!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   103
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   104
addProcess: aProcess 
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   105
    instVarAccess critical: [ processesEntered add: aProcess ].
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   106
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   107
    "Created: / 20-11-2011 / 20:30:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   108
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   109
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   110
clearOwningProcess
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   111
    instVarAccess critical: [ owningProcess := nil ].
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   112
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   113
    "Created: / 20-11-2011 / 20:34:27 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   114
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   115
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   116
decrement
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   117
    "owning process released monitor, lets lower our counter so we know how many times
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   118
     do we have to release it"
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   119
    
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   120
    instVarAccess critical: [ count := count - 1 ].
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   121
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   122
    "Created: / 22-11-2011 / 10:49:33 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   123
!
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   124
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   125
disableWait
1490
098c357e3c2f - JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents: 1199
diff changeset
   126
    Logger log: ('Waiting is disabled on monitor for %1' bindWith: ownerPrintString) severity:#debug facility:#JVM.
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   127
    instVarAccess critical: [ waitEnabled := false ].
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   128
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   129
    "Created: / 30-11-2011 / 20:34:40 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1490
098c357e3c2f - JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents: 1199
diff changeset
   130
    "Modified: / 10-05-2012 / 00:24:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   131
!
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   132
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   133
enableWait
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   134
instVarAccess critical: [waitEnabled := true].
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   135
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   136
    "Created: / 30-11-2011 / 20:34:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   137
!
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   138
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   139
increment
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   140
    "owning process entered monitor again (recursion ...), lets raise our counter so we know how many times
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   141
     do we have to release it"
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   142
    
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   143
    instVarAccess critical: [ count := count + 1 ].
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   144
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   145
    "Created: / 22-11-2011 / 10:49:07 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1689
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   146
    "Modified: / 27-08-2012 / 10:42:11 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   147
!
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   148
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   149
owningProcess: aProcess 
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   150
    instVarAccess critical: [ owningProcess := aProcess ].
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   151
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   152
    "Created: / 20-11-2011 / 20:32:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   153
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   154
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   155
processesWaitingAdd: aProcess 
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   156
    instVarAccess 
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   157
        critical: [
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   158
            self assert: (processesWaiting includesKey: aProcess) not.
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   159
            processesWaiting at: aProcess put: count
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   160
        ].
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   161
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   162
    "Created: / 22-11-2011 / 11:57:50 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   163
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   164
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   165
processesWaitingRestore: aProcess 
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   166
    instVarAccess 
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   167
        critical: [
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   168
            self assert: (processesWaiting includesKey: aProcess).
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   169
            self reinitCounter: (processesWaiting at: aProcess).
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   170
            processesWaiting removeKey: aProcess
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   171
        ].
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   172
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   173
    "Created: / 22-11-2011 / 12:59:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   174
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   175
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   176
reinitCounter
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   177
    "owning process is different from previous, lets start counting from beginning"
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   178
    
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   179
    instVarAccess critical: [ count := 1 ].
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   180
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   181
    "Created: / 22-11-2011 / 10:51:09 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   182
!
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   183
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   184
reinitCounter: newCount 
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   185
    instVarAccess critical: [ count := newCount ].
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   186
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   187
    "Created: / 22-11-2011 / 13:00:51 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   188
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   189
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   190
removeProcess: aProcess 
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   191
    instVarAccess 
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   192
        critical: [
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   193
            self assert: processesEntered last == aProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   194
            processesEntered remove: aProcess
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   195
        ].
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   196
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   197
    "Created: / 20-11-2011 / 20:28:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   198
!
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   199
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   200
waitEnabled
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   201
    instVarAccess critical: [ ^ waitEnabled].
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   202
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   203
    "Created: / 30-11-2011 / 20:34:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   204
! !
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   205
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   206
!JavaMonitor methodsFor:'initialization'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   207
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   208
initialize
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   209
    owningProcess := nil.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   210
    processesEntered := OrderedCollection new.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   211
    monitorSema := Semaphore new: 1.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   212
    processesWaiting := Dictionary new.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   213
    waitingSema := Semaphore new: 0.
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   214
    waitEnabled.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   215
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   216
    "Created: / 20-11-2011 / 13:28:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   217
!
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   218
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   219
initializeFor: owningObject
1689
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   220
    self initializeFor: owningObject thread: 0 nestedLockCount: 0.
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   221
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   222
    "Created: / 30-11-2011 / 20:39:31 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   223
    "Modified: / 26-08-2012 / 17:25:55 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   224
!
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   225
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   226
initializeFor: owningObject thread: threadId nestedLockCount: cnt 
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   227
    "/    self assert: (owningObject isJavaObject or:[owningObject isJavaClass]).
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   228
    instVarAccess := RecursionLock forMutualExclusion.
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   229
    processesEntered := OrderedCollection new.
1689
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   230
    waitEnabled := true.
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   231
    processesWaiting := Dictionary new.
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   232
    waitingSema := Semaphore new: 0.
1689
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   233
    ownerPrintString := owningObject class name , '@' 
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   234
            , owningObject identityHash printString.
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   235
    
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   236
    "/Not locked...    
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   237
    
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   238
    threadId == 0 ifTrue: [
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   239
        monitorSema := Semaphore new: 1.
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   240
        count := 0.
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   241
        ^ self.
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   242
    ] ifFalse: [
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   243
        "threadId is not zero (zero is threadId of scheduler process, which will never try to acquire the monitor)"
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   244
        "so it means it is possible that the thin lock is already locked for other thread, we must be careful "
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   245
        owningProcess := Process findProcessWithId: threadId.
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   246
        self assert: owningProcess notNil.
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   247
        processesEntered add: owningProcess.
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   248
        cnt timesRepeat: [
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   249
            "/            JavaVM enteredMonitorsOf:  owningProcess add: owningObject.
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   250
            "/            JavaVM acquiredMonitorsOf: owningProcess add: owningObject.
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   251
        ].
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   252
        monitorSema := Semaphore new: 0.
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   253
        count := cnt.
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   254
    ].
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   255
1689
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   256
    "Created: / 26-08-2012 / 17:02:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   257
    "Modified: / 28-08-2012 / 18:01:47 / m"
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   258
! !
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   259
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   260
!JavaMonitor methodsFor:'public'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   261
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   262
acquire
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   263
    | thisProcess |
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   264
    thisProcess := self activeProcess.
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   265
    (self isOwnedBy: thisProcess) ifTrue: [
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   266
        self increment.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   267
        ^ self
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   268
    ].
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   269
    monitorSema wait.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   270
    self owningProcess: thisProcess.
1689
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   271
    count := 1.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   272
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   273
    "Created: / 20-11-2011 / 13:21:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1689
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   274
    "Modified: / 27-08-2012 / 11:45:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   275
!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   276
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   277
enter
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   278
    | thisProcess |
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   279
    thisProcess := self activeProcess.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   280
    self addProcess: thisProcess.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   281
    self acquire.
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   282
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   283
    "Created: / 20-11-2011 / 13:21:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   284
!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   285
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   286
exit
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   287
    | thisProcess |
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   288
    thisProcess := self activeProcess.
1169
8f727dc66647 monitor fix.. many to come :)
hlopkmar
parents: 1159
diff changeset
   289
    (self isOwnedBy: thisProcess) ifTrue: [ self release. ].    
8f727dc66647 monitor fix.. many to come :)
hlopkmar
parents: 1159
diff changeset
   290
    processesEntered remove: thisProcess ifAbsent: nil.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   291
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   292
    "Created: / 20-11-2011 / 13:21:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1689
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   293
    "Modified: / 26-08-2012 / 19:54:14 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   294
!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   295
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   296
notify
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   297
    "wakeup one waiting process"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   298
    
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   299
    | thisProcess |
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   300
    thisProcess := Processor activeProcess.
1179
26fa6829e4d7 small changes is monitors + more logging
hlopkmar
parents: 1172
diff changeset
   301
    self assert: (self isOwnedBy: thisProcess).
26fa6829e4d7 small changes is monitors + more logging
hlopkmar
parents: 1172
diff changeset
   302
    Logger 
1198
2f3bec682673 discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents: 1195
diff changeset
   303
        log: ('%1: notifying %2 processes' bindWith: thisProcess printString
2f3bec682673 discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents: 1195
diff changeset
   304
                with: processesWaiting size)
1179
26fa6829e4d7 small changes is monitors + more logging
hlopkmar
parents: 1172
diff changeset
   305
        severity: #debug
26fa6829e4d7 small changes is monitors + more logging
hlopkmar
parents: 1172
diff changeset
   306
        facility: #JVM.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   307
    waitingSema signal.
1198
2f3bec682673 discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents: 1195
diff changeset
   308
    Processor yield.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   309
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   310
    "Created: / 22-11-2011 / 12:14:23 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   311
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   312
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   313
notifyAll
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   314
    "wakeup one waiting process"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   315
    
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   316
    | thisProcess |
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   317
    thisProcess := Processor activeProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   318
    self assert: (self isOwnedBy: thisProcess).
1181
36396857af53 more logging for monitors, do you have the feeling that I'm desperate? :)
hlopkmar
parents: 1179
diff changeset
   319
    Logger 
1199
5f123f80c1ed notifyAll needs yield too
hlopkmar
parents: 1198
diff changeset
   320
        log: ('%1: notifying all %2 processes' bindWith: thisProcess printString
5f123f80c1ed notifyAll needs yield too
hlopkmar
parents: 1198
diff changeset
   321
                with: processesWaiting size)
5f123f80c1ed notifyAll needs yield too
hlopkmar
parents: 1198
diff changeset
   322
        severity: #debug
5f123f80c1ed notifyAll needs yield too
hlopkmar
parents: 1198
diff changeset
   323
        facility: #JVM.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   324
    waitingSema signalForAll.
1199
5f123f80c1ed notifyAll needs yield too
hlopkmar
parents: 1198
diff changeset
   325
    Processor yield.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   326
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   327
    "Created: / 22-11-2011 / 12:14:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   328
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   329
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   330
release
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   331
    | thisProcess |
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   332
    thisProcess := self activeProcess.
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   333
    self assert: (self isOwnedBy: owningProcess).
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   334
    count == 1 ifTrue: [
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   335
        self clearOwningProcess.
1689
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   336
        count := 0.
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   337
        monitorSema signal.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   338
    ] ifFalse: [
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   339
        self decrement.       
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   340
    ]
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   341
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   342
    "Created: / 20-11-2011 / 13:21:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1689
5da8961dff01 - JavaMonitor
hlopkmar
parents: 1490
diff changeset
   343
    "Modified: / 27-08-2012 / 11:44:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   344
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   345
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   346
releaseAll
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   347
    count timesRepeat: [self release].
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   348
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   349
    "Created: / 22-11-2011 / 13:05:20 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   350
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   351
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   352
wait
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   353
    "make owning process to go to wait"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   354
    
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   355
    self waitForMilliseconds: nil.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   356
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   357
    "Created: / 22-11-2011 / 11:57:56 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   358
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   359
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   360
waitForMilliseconds: timeOut 
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   361
    "make owning process to go to wait, but not longer than timeout"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   362
    
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   363
    | thisProcess |
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   364
    thisProcess := Processor activeProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   365
    self assert: (self isOwnedBy: thisProcess).
1195
378d34a28bd4 need more logging
hlopkmar
parents: 1194
diff changeset
   366
    self waitEnabled ifFalse: [
378d34a28bd4 need more logging
hlopkmar
parents: 1194
diff changeset
   367
        Logger 
378d34a28bd4 need more logging
hlopkmar
parents: 1194
diff changeset
   368
            log: ('%1 wanted to go to sleep, but it cant, this monitor is for %2 which is already dead' 
378d34a28bd4 need more logging
hlopkmar
parents: 1194
diff changeset
   369
                    bindWith: thisProcess printString
1490
098c357e3c2f - JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents: 1199
diff changeset
   370
                    with: ownerPrintString)
1195
378d34a28bd4 need more logging
hlopkmar
parents: 1194
diff changeset
   371
            severity: #debug
378d34a28bd4 need more logging
hlopkmar
parents: 1194
diff changeset
   372
            facility: #JVM.
378d34a28bd4 need more logging
hlopkmar
parents: 1194
diff changeset
   373
        ^ self.
378d34a28bd4 need more logging
hlopkmar
parents: 1194
diff changeset
   374
    ].
1179
26fa6829e4d7 small changes is monitors + more logging
hlopkmar
parents: 1172
diff changeset
   375
    Logger 
1195
378d34a28bd4 need more logging
hlopkmar
parents: 1194
diff changeset
   376
        log: ('%1 is going to wait on %3 for timeout: %2' 
1194
9f910257b6e8 from now on joining thread does not block after threads death
hlopkmar
parents: 1181
diff changeset
   377
                bindWith: thisProcess printString
1198
2f3bec682673 discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents: 1195
diff changeset
   378
                with: timeOut
1490
098c357e3c2f - JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents: 1199
diff changeset
   379
                with: ownerPrintString printString)
1181
36396857af53 more logging for monitors, do you have the feeling that I'm desperate? :)
hlopkmar
parents: 1179
diff changeset
   380
        severity: #debug
36396857af53 more logging for monitors, do you have the feeling that I'm desperate? :)
hlopkmar
parents: 1179
diff changeset
   381
        facility: #JVM.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   382
    self processesWaitingAdd: thisProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   383
    self releaseAll.
1169
8f727dc66647 monitor fix.. many to come :)
hlopkmar
parents: 1159
diff changeset
   384
     "JV@2011-11-25: zero timeout means wait without timeout!!!!!!"
8f727dc66647 monitor fix.. many to come :)
hlopkmar
parents: 1159
diff changeset
   385
    timeOut == 0 ifTrue: [ waitingSema wait ] ifFalse: [
1159
afe8ab363ca3 Mainly fixes:
vranyj1
parents: 1155
diff changeset
   386
        waitingSema waitWithTimeoutMs: timeOut
afe8ab363ca3 Mainly fixes:
vranyj1
parents: 1155
diff changeset
   387
    ].
1179
26fa6829e4d7 small changes is monitors + more logging
hlopkmar
parents: 1172
diff changeset
   388
    Logger 
1198
2f3bec682673 discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents: 1195
diff changeset
   389
        log: ('%1 has been notified and is trying to acquire monitor for %2 which is owned by %3' 
1490
098c357e3c2f - JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents: 1199
diff changeset
   390
                bindWith: thisProcess printString with: ownerPrintString printString with: owningProcess printString)
1179
26fa6829e4d7 small changes is monitors + more logging
hlopkmar
parents: 1172
diff changeset
   391
        severity: #debug
26fa6829e4d7 small changes is monitors + more logging
hlopkmar
parents: 1172
diff changeset
   392
        facility: #JVM.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   393
    self acquire.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   394
    self processesWaitingRestore: thisProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   395
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   396
    "Created: / 22-11-2011 / 12:52:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1198
2f3bec682673 discovered biggest bug of them all.. daemon mauve test passes
hlopkmar
parents: 1195
diff changeset
   397
    "Modified: / 01-12-2011 / 10:57:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1490
098c357e3c2f - JavaMonitor: do not keep reference back to the owner as this
vranyj1
parents: 1199
diff changeset
   398
    "Modified: / 10-05-2012 / 00:24:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   399
! !
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   400
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   401
!JavaMonitor methodsFor:'queries'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   402
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   403
isAcquired
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   404
    ^ instVarAccess critical: [ owningProcess notNil ].
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   405
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   406
    "Created: / 20-11-2011 / 13:22:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   407
!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   408
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   409
isOwnedBy: aProcess 
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   410
    ^ instVarAccess critical: [ owningProcess == aProcess ].
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   411
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   412
    "Created: / 20-11-2011 / 13:23:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   413
! !
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   414
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   415
!JavaMonitor class methodsFor:'documentation'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   416
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   417
version_SVN
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   418
    ^ '$Id$'
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   419
! !
1172
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   420
7795b5618017 Java monitors are now even more synchronized
hlopkmar
parents: 1169
diff changeset
   421
JavaMonitor initialize!