Skip to content

Commit 4f0af16

Browse files
author
lukas.molzberger
committed
- fixed race condition
1 parent 7586ba4 commit 4f0af16

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

core/src/main/java/network/aika/elements/neurons/NeuronProvider.java

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -109,35 +109,43 @@ public Model getModel() {
109109
return model;
110110
}
111111

112-
public synchronized void increaseRefCount(RefType rt) {
113-
refCount++;
114-
refCountByType[rt.ordinal()]++;
115-
116-
if(!isRegistered && refCount > 0) {
117-
model.register(this);
118-
isRegistered = true;
112+
public void increaseRefCount(RefType rt) {
113+
synchronized (refCountByType) {
114+
refCount++;
115+
refCountByType[rt.ordinal()]++;
116+
117+
if (!isRegistered && refCount > 0) {
118+
model.register(this);
119+
isRegistered = true;
120+
}
119121
}
120122
}
121123

122-
public synchronized void decreaseRefCount(RefType rt) {
123-
refCount--;
124-
refCountByType[rt.ordinal()]--;
124+
public void decreaseRefCount(RefType rt) {
125+
synchronized (refCountByType) {
126+
refCount--;
127+
refCountByType[rt.ordinal()]--;
125128

126-
assert refCount >= 0;
127-
assert refCountByType[rt.ordinal()] >= 0;
129+
assert refCount >= 0;
130+
assert refCountByType[rt.ordinal()] >= 0;
128131

129-
if(isRegistered && refCount == 0) {
130-
model.unregister(this);
131-
isRegistered = false;
132+
if (isRegistered && refCount == 0) {
133+
model.unregister(this);
134+
isRegistered = false;
135+
}
132136
}
133137
}
134138

135-
public synchronized int getRefCount() {
136-
return refCount;
139+
public int getRefCount() {
140+
synchronized (refCountByType) {
141+
return refCount;
142+
}
137143
}
138144

139145
public boolean isReferenced() {
140-
return refCount > 0;
146+
synchronized (refCountByType) {
147+
return refCount > 0;
148+
}
141149
}
142150

143151
public boolean isSuspended() {

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777

7878

7979
<properties>
80-
<revision>2.0.9-rc27</revision>
80+
<revision>2.0.9-rc28</revision>
8181

8282
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
8383

0 commit comments

Comments
 (0)