blob: 26263cdf36aaa92876babbda98cc5414238201fd [file] [log] [blame]
/*********************************************************************
* Copyright (c) 2018 The University of York.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
**********************************************************************/
package org.eclipse.epsilon.ecl.execute.context.concurrent;
import org.eclipse.epsilon.ecl.IEclModule;
import org.eclipse.epsilon.ecl.execute.context.IEclContext;
import org.eclipse.epsilon.ecl.trace.MatchTrace;
import org.eclipse.epsilon.eol.exceptions.concurrent.EolNestedParallelismException;
import org.eclipse.epsilon.eol.execute.concurrent.PersistentThreadLocal;
import org.eclipse.epsilon.eol.execute.context.concurrent.IEolContextParallel;
import org.eclipse.epsilon.erl.execute.context.concurrent.ErlContextParallel;
public class EclContextParallel extends ErlContextParallel implements IEclContextParallel {
protected PersistentThreadLocal<MatchTrace> tempMatchTraces;
protected MatchTrace matchTrace;
public EclContextParallel() {
this(0);
}
public EclContextParallel(int parallelism) {
super(parallelism, true);
}
public EclContextParallel(IEclContext other) {
super(other, true);
this.matchTrace = new MatchTrace(other.getMatchTrace());
}
@Override
protected void initMainThreadStructures() {
super.initMainThreadStructures();
matchTrace = new MatchTrace(true);
}
@Override
protected void initThreadLocals() {
super.initThreadLocals();
tempMatchTraces = new PersistentThreadLocal<>(MatchTrace::new);
}
@Override
public void setMatchTrace(MatchTrace matchTrace) {
this.matchTrace = matchTrace;
}
@Override
public MatchTrace getMatchTrace() {
return matchTrace;
}
@Override
public MatchTrace getTempMatchTrace() {
return parallelGet(tempMatchTraces, () -> null);
}
@Override
public IEclModule getModule() {
return (IEclModule) module;
}
public static IEclContextParallel convertToParallel(IEclContext context_) throws EolNestedParallelismException {
return IEolContextParallel.copyToParallel(context_, EclContextParallel::new);
}
}