Skip to content

Commit ddc70de

Browse files
committed
fixing thread barrier
1 parent 0f3512a commit ddc70de

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

modules/siddhi-core/src/main/java/org/wso2/siddhi/core/util/ThreadBarrier.java

+7-22
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,25 @@
1818

1919
package org.wso2.siddhi.core.util;
2020

21-
import java.util.concurrent.locks.Lock;
2221
import java.util.concurrent.locks.ReentrantLock;
2322

2423
public class ThreadBarrier {
2524

26-
private volatile Lock lock = null;
25+
private ReentrantLock lock = new ReentrantLock();
2726

2827
public void pass() {
29-
if (lock != null) {
30-
synchronized (this) {
31-
if (lock != null) {
32-
lock.lock();
33-
lock.unlock();
34-
}
35-
}
28+
if (lock.isLocked()) {
29+
lock.lock();
30+
lock.unlock();
3631
}
3732
}
3833

39-
public synchronized void lock() {
40-
if (lock == null) {
41-
lock = new ReentrantLock();
42-
}
34+
public void lock() {
4335
lock.lock();
44-
4536
}
4637

47-
public synchronized void unlock() {
48-
if (lock != null) {
49-
try {
50-
} finally {
51-
lock.unlock();
52-
}
53-
lock = null;
54-
}
38+
public void unlock() {
39+
lock.unlock();
5540
}
5641

5742
}

0 commit comments

Comments
 (0)