use of org.metaborg.util.concurrent.IClosableLock in project spoofax by metaborg.
the class AbstractScopeGraphContext method writeLock.
private IClosableLock writeLock() {
final Lock writeLock = lock.writeLock();
final IClosableLock lock = new ClosableLock(writeLock);
return lock;
}
use of org.metaborg.util.concurrent.IClosableLock in project spoofax by metaborg.
the class IndexTaskContext method unload.
@Override
public void unload() {
if (index == null && taskEngine == null) {
return;
}
try (IClosableLock lock = writeLock()) {
index = null;
taskEngine = null;
}
}
use of org.metaborg.util.concurrent.IClosableLock in project spoofax by metaborg.
the class IndexTaskContext method read.
@Override
public IClosableLock read() {
if (index == null || taskEngine == null) {
// THREADING: temporarily acquire a write lock when initializing the index, need exclusive access.
try (IClosableLock lock = writeLock()) {
/*
* THREADING: re-check if index/task engine are still null now that we have exclusive access, there
* could have been a context switch before acquiring the lock. Check is also needed because the null
* check before is disjunct.
*/
if (index == null) {
index = loadIndex();
}
if (taskEngine == null) {
taskEngine = loadTaskEngine();
}
}
}
index.recover();
taskEngine.recover();
return readLock();
}
use of org.metaborg.util.concurrent.IClosableLock in project spoofax by metaborg.
the class IndexTaskContext method reset.
@Override
public void reset() throws FileSystemException {
try (IClosableLock lock = writeLock()) {
if (index != null) {
index.reset();
index = null;
}
if (taskEngine != null) {
taskEngine.reset();
taskEngine = null;
}
final FileObject indexFile = indexFile();
indexFile.delete();
final FileObject taskEngineFile = taskEngineFile();
taskEngineFile.delete();
}
}
use of org.metaborg.util.concurrent.IClosableLock in project spoofax by metaborg.
the class IndexTaskContext method write.
@Override
public IClosableLock write() {
final IClosableLock lock = writeLock();
if (index == null) {
index = loadIndex();
}
if (taskEngine == null) {
taskEngine = loadTaskEngine();
}
index.recover();
taskEngine.recover();
return lock;
}
Aggregations