Add debug logs to project lock mechanism

This commit is contained in:
Simon Detheridge 2021-07-08 12:14:52 +01:00
parent a3c4f8c4e6
commit 3b27a2ee6a

View file

@ -7,6 +7,7 @@ import java.util.Map;
import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import uk.ac.ic.wlgitbridge.util.Log;
/** /**
* Created by Winston on 20/11/14. * Created by Winston on 20/11/14.
@ -35,29 +36,40 @@ public class ProjectLockImpl implements ProjectLock {
@Override @Override
public void lockForProject(String projectName) { public void lockForProject(String projectName) {
Log.debug("[{}] taking project lock", projectName);
getLockForProjectName(projectName).lock(); getLockForProjectName(projectName).lock();
Log.debug("[{}] taking reentrant lock", projectName);
rlock.lock(); rlock.lock();
Log.debug("[{}] taken locks", projectName);
} }
@Override @Override
public void unlockForProject(String projectName) { public void unlockForProject(String projectName) {
Log.debug("[{}] releasing project lock", projectName);
getLockForProjectName(projectName).unlock(); getLockForProjectName(projectName).unlock();
Log.debug("[{}] releasing reentrant lock", projectName);
rlock.unlock(); rlock.unlock();
Log.debug("[{}] released locks", projectName);
if (waiting) { if (waiting) {
Log.debug("[{}] waiting for remaining threads", projectName);
trySignal(); trySignal();
} }
} }
private void trySignal() { private void trySignal() {
int threads = rwlock.getReadLockCount(); int threads = rwlock.getReadLockCount();
Log.debug("-> waiting for {} threads", threads);
if (waiter != null && threads > 0) { if (waiter != null && threads > 0) {
waiter.threadsRemaining(threads); waiter.threadsRemaining(threads);
} }
Log.debug("-> finished waiting for threads");
} }
public void lockAll() { public void lockAll() {
Log.debug("-> locking all threads");
waiting = true; waiting = true;
trySignal(); trySignal();
Log.debug("-> locking reentrant write lock");
wlock.lock(); wlock.lock();
} }