Search in sources :

Example 6 with IClosableLock

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;
}
Also used : ClosableLock(org.metaborg.util.concurrent.ClosableLock) IClosableLock(org.metaborg.util.concurrent.IClosableLock) IClosableLock(org.metaborg.util.concurrent.IClosableLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) Lock(java.util.concurrent.locks.Lock) ClosableLock(org.metaborg.util.concurrent.ClosableLock) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) IClosableLock(org.metaborg.util.concurrent.IClosableLock)

Example 7 with IClosableLock

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;
    }
}
Also used : IClosableLock(org.metaborg.util.concurrent.IClosableLock)

Example 8 with IClosableLock

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();
}
Also used : IClosableLock(org.metaborg.util.concurrent.IClosableLock)

Example 9 with IClosableLock

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();
    }
}
Also used : IClosableLock(org.metaborg.util.concurrent.IClosableLock) FileObject(org.apache.commons.vfs2.FileObject)

Example 10 with IClosableLock

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;
}
Also used : IClosableLock(org.metaborg.util.concurrent.IClosableLock)

Aggregations

IClosableLock (org.metaborg.util.concurrent.IClosableLock)15 FileObject (org.apache.commons.vfs2.FileObject)6 Lock (java.util.concurrent.locks.Lock)4 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)4 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)4 IContext (org.metaborg.core.context.IContext)4 ClosableLock (org.metaborg.util.concurrent.ClosableLock)4 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)3 ITermFactory (org.spoofax.interpreter.terms.ITermFactory)3 Collection (java.util.Collection)2 FileName (org.apache.commons.vfs2.FileName)2 MetaborgException (org.metaborg.core.MetaborgException)2 AnalysisException (org.metaborg.core.analysis.AnalysisException)2 ILanguageImpl (org.metaborg.core.language.ILanguageImpl)2 IProject (org.metaborg.core.project.IProject)2 ISourceRegion (org.metaborg.core.source.ISourceRegion)2 SourceRegion (org.metaborg.core.source.SourceRegion)2 TermWithRegion (org.metaborg.spoofax.core.tracing.TracingCommon.TermWithRegion)2 HybridInterpreter (org.strategoxt.HybridInterpreter)2 IOException (java.io.IOException)1