mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Add debug logs to project lock mechanism
This commit is contained in:
parent
a3c4f8c4e6
commit
3b27a2ee6a
1 changed files with 12 additions and 0 deletions
|
@ -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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue