src/JavaMonitor.st
author hlopkmar
Mon, 28 Nov 2011 13:03:05 +0000
branchjk_new_structure
changeset 1169 8f727dc66647
parent 1159 afe8ab363ca3
child 1172 7795b5618017
permissions -rw-r--r--
monitor fix.. many to come :)
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
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    24
	instanceVariableNames:'owningProcess processesEntered monitorSema processesEnteredAccess
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
    25
		owningProcessAccess count countAccess waitingSema
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
    26
		processesWaitingAccess processesWaiting'
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    27
	classVariableNames:''
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    28
	poolDictionaries:''
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    29
	category:'Languages-Java-Support'
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    30
!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    31
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    32
!JavaMonitor class methodsFor:'documentation'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    33
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    34
copyright
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    35
"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    36
 COPYRIGHT (c) 1996-2011 by Claus Gittinger
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1148
diff changeset
    37
1155
vranyj1
parents: 1152
diff changeset
    38
 New code and modifications done at SWING Research Group [1]:
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1148
diff changeset
    39
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    40
 COPYRIGHT (c) 2010-2011 by Jan Vrany, Jan Kurs and Marcel Hlopko
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    41
                            SWING Research Group, Czech Technical University in Prague
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    42
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    43
 This software is furnished under a license and may be used
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    44
 only in accordance with the terms of that license and with the
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    45
 inclusion of the above copyright notice.   This software may not
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    46
 be provided or otherwise made available to, or used by, any
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    47
 other person.  No title to or ownership of the software is
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    48
 hereby transferred.
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    49
1155
vranyj1
parents: 1152
diff changeset
    50
 [1] Code written at SWING Research Group contains a signature
vranyj1
parents: 1152
diff changeset
    51
     of one of the above copright owners. For exact set of such code,
vranyj1
parents: 1152
diff changeset
    52
     see the differences between this version and version stx:libjava
1152
040cba55a7d2 Copyright fixes
vranyj1
parents: 1148
diff changeset
    53
     as of 1.9.2010
1142
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
! !
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    57
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    58
!JavaMonitor class methodsFor:'instance creation'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    59
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    60
new
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    61
^self basicNew initialize.
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    62
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    63
    "Created: / 20-11-2011 / 14:30:36 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    64
! !
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    65
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    66
!JavaMonitor methodsFor:'accessing'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    67
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    68
activeProcess
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    69
    ^ Processor activeProcess
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    70
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    71
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    72
copyProcessesEntered
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    73
    ^ processesEntered copy.
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    74
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    75
    "Created: / 20-11-2011 / 14:45:24 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    76
!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    77
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    78
processesEntered
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    79
    "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
    80
    ^ processesEntered.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    81
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    82
    "Created: / 20-11-2011 / 13:22:15 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    83
! !
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
    84
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    85
!JavaMonitor methodsFor:'atomic'!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    86
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    87
addProcess: aProcess
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    88
    processesEnteredAccess critical: [processesEntered add: aProcess].
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    89
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    90
    "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
    91
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    92
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    93
clearOwningProcess
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    94
    owningProcessAccess critical: [ owningProcess := nil ].
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    95
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    96
    "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
    97
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
    98
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
    99
decrement
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   100
    "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
   101
     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
   102
    
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   103
    countAccess critical: [ count := count - 1 ].
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   104
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   105
    "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
   106
!
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   107
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   108
increment
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   109
    "owning process entered monitor again (recursion ...), lets raise 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
   110
    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
   111
    countAccess critical: [ count := count + 1 ].
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   112
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   113
    "Created: / 22-11-2011 / 10:49:07 / 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
   114
!
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   115
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   116
owningProcess: aProcess
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   117
owningProcessAccess critical: [owningProcess := aProcess].
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   118
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   119
    "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
   120
!
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   121
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   122
processesWaitingAdd: aProcess 
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   123
    processesWaitingAccess 
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   124
        critical: [ self assert: (processesWaiting includesKey: aProcess) not.processesWaiting at: aProcess put: count ].
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   125
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   126
    "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
   127
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   128
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   129
processesWaitingRestore: aProcess 
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   130
   processesWaitingAccess 
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   131
   critical: [
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   132
   self assert: (processesWaiting includesKey: aProcess).
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   133
   self reinitCounter: (processesWaiting at: aProcess).   
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   134
   processesWaiting removeKey: aProcess
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   135
           ].
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   136
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   137
    "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
   138
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   139
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   140
reinitCounter
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   141
    "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
   142
    
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   143
    countAccess critical: [ count := 1 ].
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: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
   146
!
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   147
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   148
reinitCounter: newCount 
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   149
    countAccess critical: [ count := newCount ].
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   150
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   151
    "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
   152
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   153
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   154
removeProcess: aProcess 
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   155
    processesEnteredAccess 
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   156
        critical: [
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   157
            self assert: processesEntered last == aProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   158
            processesEntered remove: aProcess
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   159
        ].
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   160
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   161
    "Created: / 20-11-2011 / 20:28:37 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   162
! !
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   163
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   164
!JavaMonitor methodsFor:'initialization'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   165
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   166
initialize
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   167
    owningProcess := nil.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   168
    owningProcessAccess := Semaphore forMutualExclusion.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   169
    processesEntered := OrderedCollection new.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   170
    processesEnteredAccess := Semaphore forMutualExclusion.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   171
    monitorSema := Semaphore new: 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
   172
    countAccess := Semaphore forMutualExclusion.
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   173
    processesWaiting := Dictionary new.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   174
    processesWaitingAccess := Semaphore forMutualExclusion.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   175
    waitingSema := Semaphore new: 0.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   176
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   177
    "Created: / 20-11-2011 / 13:28:28 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   178
! !
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   179
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   180
!JavaMonitor methodsFor:'public'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   181
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   182
acquire
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   183
    | thisProcess |
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   184
    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
   185
    (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
   186
        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
   187
        ^ self
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   188
    ].
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   189
    monitorSema wait.
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   190
    self owningProcess: thisProcess.
1145
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   191
    self reinitCounter.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   192
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   193
    "Created: / 20-11-2011 / 13:21:46 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   194
!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   195
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   196
enter
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   197
    | thisProcess |
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   198
    thisProcess := self activeProcess.
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   199
    self addProcess: thisProcess.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   200
    self acquire.
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   201
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   202
    "Created: / 20-11-2011 / 13:21:42 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   203
!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   204
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   205
exit
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   206
    | thisProcess |
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   207
    thisProcess := self activeProcess.
1169
8f727dc66647 monitor fix.. many to come :)
hlopkmar
parents: 1159
diff changeset
   208
    (self isOwnedBy: thisProcess) ifTrue: [ self release. ].    
8f727dc66647 monitor fix.. many to come :)
hlopkmar
parents: 1159
diff changeset
   209
    processesEntered remove: thisProcess ifAbsent: nil.
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   210
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   211
    "Created: / 20-11-2011 / 13:21:54 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   212
!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   213
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   214
notify
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   215
    "wakeup one waiting process"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   216
    
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   217
    | thisProcess |
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   218
    thisProcess := Processor activeProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   219
    self assert: (self isOwnedBy: thisProcess).        
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   220
    waitingSema signal.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   221
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   222
    "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
   223
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   224
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   225
notifyAll
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   226
    "wakeup one waiting process"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   227
    
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   228
    | thisProcess |
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   229
    thisProcess := Processor activeProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   230
    self assert: (self isOwnedBy: thisProcess).
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   231
    waitingSema signalForAll.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   232
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   233
    "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
   234
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   235
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   236
release
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   237
    | thisProcess |
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   238
    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
   239
    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
   240
    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
   241
        self clearOwningProcess.
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   242
        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
   243
    ] ifFalse: [
8728f5373a48 end of the old monitors has come, new monitors plugged in, not yet bugfree I'm sure
hlopkmar
parents: 1144
diff changeset
   244
        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
   245
    ]
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   246
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   247
    "Created: / 20-11-2011 / 13:21:52 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   248
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   249
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   250
releaseAll
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   251
    count timesRepeat: [self release].
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   252
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   253
    "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
   254
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   255
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   256
wait
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   257
    "make owning process to go to wait"
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   258
    
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   259
    self waitForMilliseconds: nil.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   260
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   261
    "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
   262
!
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   263
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   264
waitForMilliseconds: timeOut 
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   265
    "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
   266
    
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   267
    | thisProcess |
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   268
    thisProcess := Processor activeProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   269
    self assert: (self isOwnedBy: thisProcess).
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   270
    self processesWaitingAdd: thisProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   271
    self releaseAll.
1169
8f727dc66647 monitor fix.. many to come :)
hlopkmar
parents: 1159
diff changeset
   272
     "JV@2011-11-25: zero timeout means wait without timeout!!!!!!"
8f727dc66647 monitor fix.. many to come :)
hlopkmar
parents: 1159
diff changeset
   273
    timeOut == 0 ifTrue: [ waitingSema wait ] ifFalse: [
1159
afe8ab363ca3 Mainly fixes:
vranyj1
parents: 1155
diff changeset
   274
        waitingSema waitWithTimeoutMs: timeOut
afe8ab363ca3 Mainly fixes:
vranyj1
parents: 1155
diff changeset
   275
    ].
1146
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   276
    self acquire.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   277
    self processesWaitingRestore: thisProcess.
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   278
e458dd16772e java monitors now know wait, notify, notifyall
hlopkmar
parents: 1145
diff changeset
   279
    "Created: / 22-11-2011 / 12:52:45 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1159
afe8ab363ca3 Mainly fixes:
vranyj1
parents: 1155
diff changeset
   280
    "Modified (comment): / 25-11-2011 / 18:30:59 / Jan Vrany <jan.vrany@fit.cvut.cz>"
1169
8f727dc66647 monitor fix.. many to come :)
hlopkmar
parents: 1159
diff changeset
   281
    "Modified: / 28-11-2011 / 14:01:25 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   282
! !
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   283
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   284
!JavaMonitor methodsFor:'queries'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   285
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   286
isAcquired
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   287
    ^ owningProcessAccess critical: [owningProcess notNil].
1142
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   288
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   289
    "Created: / 20-11-2011 / 13:22:26 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   290
!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   291
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   292
isOwnedBy: aProcess 
1143
5e1de8c6b43e JavaMonitor more or less finished.. integration coming soon
hlopkmar
parents: 1142
diff changeset
   293
    ^ owningProcessAccess critical: [ owningProcess == aProcess ].
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
    "Created: / 20-11-2011 / 13:23:14 / Marcel Hlopko <hlopkmar@fel.cvut.cz>"
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   296
! !
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   297
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   298
!JavaMonitor class methodsFor:'documentation'!
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   299
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   300
version_SVN
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   301
    ^ '$Id$'
1a1ce9fd0a16 java monitors (not plugged in yet)
hlopkmar
parents:
diff changeset
   302
! !