fix for concurrent access exceptions

This commit is contained in:
d-millar 2021-01-05 20:31:57 +00:00
parent cd32ab60be
commit c4f1ec8e0a
6 changed files with 71 additions and 50 deletions

View file

@ -123,7 +123,11 @@ public class DbgManagerImpl implements DbgManager {
public DbgThreadImpl getThreadComputeIfAbsent(DebugThreadId id, DbgProcessImpl process,
int tid) {
synchronized (threads) {
return threads.computeIfAbsent(id, i -> new DbgThreadImpl(this, process, id, tid));
if (!threads.containsKey(id)) {
DbgThreadImpl thread = new DbgThreadImpl(this, process, id, tid);
thread.add();
}
return threads.get(id);
}
}
@ -188,7 +192,11 @@ public class DbgManagerImpl implements DbgManager {
public DbgProcessImpl getProcessComputeIfAbsent(DebugProcessId id, int pid) {
synchronized (processes) {
return processes.computeIfAbsent(id, i -> new DbgProcessImpl(this, id, pid));
if (!processes.containsKey(id)) {
DbgProcessImpl process = new DbgProcessImpl(this, id, pid);
process.add();
}
return processes.get(id);
}
}
@ -221,7 +229,11 @@ public class DbgManagerImpl implements DbgManager {
public DbgSessionImpl getSessionComputeIfAbsent(DebugSessionId id) {
synchronized (sessions) {
return sessions.computeIfAbsent(id, i -> new DbgSessionImpl(this, id));
if (!sessions.containsKey(id)) {
DbgSessionImpl session = new DbgSessionImpl(this, id);
session.add();
}
return sessions.get(id);
}
}
@ -720,7 +732,7 @@ public class DbgManagerImpl implements DbgManager {
so.setCurrentProcessId(id);
int pid = so.getCurrentProcessSystemId();
DbgProcessImpl proc = new DbgProcessImpl(this, id, pid);
proc.add(evt.getCause());
proc.add();
getEventListeners().fire.processAdded(proc, evt.getCause());
getEventListeners().fire.processSelected(proc, evt.getCause());
@ -1325,50 +1337,62 @@ public class DbgManagerImpl implements DbgManager {
}
public DbgThreadImpl getCurrentThread() {
DebugEventInformation info = getLastEventInformation();
if (info == null) {
return null;
synchronized (threads) {
DebugEventInformation info = getLastEventInformation();
if (info == null) {
return null;
}
DebugSystemObjects so = getSystemObjects();
int tid = so.getCurrentThreadSystemId();
if (tid < 0) {
return null;
}
return threads.get(info.getThreadId());
}
DebugSystemObjects so = getSystemObjects();
int tid = so.getCurrentThreadSystemId();
if (tid < 0) {
return null;
}
return threads.get(info.getThreadId());
}
public DbgProcessImpl getCurrentProcess() {
DebugEventInformation info = getLastEventInformation();
if (info == null) {
return null;
synchronized (processes) {
DebugEventInformation info = getLastEventInformation();
if (info == null) {
return null;
}
return processes.get(info.getProcessId());
}
return processes.get(info.getProcessId());
}
public DbgSessionImpl getCurrentSession() {
DebugEventInformation info = getLastEventInformation();
if (info == null) {
return null;
synchronized (sessions) {
DebugEventInformation info = getLastEventInformation();
if (info == null) {
return null;
}
return sessions.get(info.getSessionId());
}
return sessions.get(info.getSessionId());
}
public DbgThreadImpl getEventThread() {
DebugSystemObjects so = getSystemObjects();
DebugThreadId id = so.getEventThread();
return threads.get(id);
synchronized (threads) {
DebugSystemObjects so = getSystemObjects();
DebugThreadId id = so.getEventThread();
return threads.get(id);
}
}
public DbgProcessImpl getEventProcess() {
DebugSystemObjects so = getSystemObjects();
DebugProcessId id = so.getEventProcess();
return processes.get(id);
synchronized (processes) {
DebugSystemObjects so = getSystemObjects();
DebugProcessId id = so.getEventProcess();
return processes.get(id);
}
}
public DbgSessionImpl getEventSession() {
DebugSystemObjects so = getSystemObjects();
DebugSessionId id = so.getEventSystem();
return sessions.get(id);
synchronized (sessions) {
DebugSystemObjects so = getSystemObjects();
DebugSessionId id = so.getEventSystem();
return sessions.get(id);
}
}
public CompletableFuture<Void> selectThread(DbgThreadImpl thread) {

View file

@ -63,8 +63,6 @@ public class DbgProcessImpl implements DbgProcess {
this.manager = manager;
this.id = id;
this.pid = pid;
manager.processes.put(id, this);
manager.getEventListeners().fire.processAdded(this, DbgCause.Causes.UNCLAIMED);
}
public DbgProcessImpl(DbgManagerImpl manager) {
@ -109,7 +107,9 @@ public class DbgProcessImpl implements DbgProcess {
*
* @param cause the cause of the new inferior
*/
public void add(DbgCause cause) {
public void add() {
manager.processes.put(id, this);
manager.getEventListeners().fire.processAdded(this, DbgCause.Causes.UNCLAIMED);
//manager.addProcess(this, cause);
}

View file

@ -42,8 +42,6 @@ public class DbgSessionImpl implements DbgSession {
public DbgSessionImpl(DbgManagerImpl manager, DebugSessionId id) {
this.manager = manager;
this.id = id;
manager.sessions.put(id, this);
manager.getEventListeners().fire.sessionAdded(this, DbgCause.Causes.UNCLAIMED);
}
public DbgSessionImpl(DbgManagerImpl manager) {
@ -83,7 +81,9 @@ public class DbgSessionImpl implements DbgSession {
*
* @param cause the cause of the new inferior
*/
public void add(DbgCause cause) {
public void add() {
manager.sessions.put(id, this);
manager.getEventListeners().fire.sessionAdded(this, DbgCause.Causes.UNCLAIMED);
//manager.addSession(this, cause);
}

View file

@ -64,14 +64,6 @@ public class DbgThreadImpl implements DbgThread {
this.process = process;
this.id = id;
this.tid = tid;
manager.threads.put(id, this);
manager.getEventListeners().fire.threadCreated(this, DbgCause.Causes.UNCLAIMED);
}
public DbgThreadImpl(DbgManagerImpl manager, DbgProcessImpl process, DebugThreadId id, long tid,
DebugEventInformation info) {
this(manager, process, id, tid);
this.setInfo(info);
}
@Override
@ -98,6 +90,8 @@ public class DbgThreadImpl implements DbgThread {
* Add this thread to the inferior and manager
*/
public void add() {
manager.threads.put(id, this);
manager.getEventListeners().fire.threadCreated(this, DbgCause.Causes.UNCLAIMED);
process.addThread(this);
state.addChangeListener((oldState, newState, pair) -> {
this.manager.getEventListeners().fire.threadStateChanged(this, newState, pair.cause,

View file

@ -19,7 +19,6 @@ import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import agent.dbgeng.dbgeng.DebugSessionId;
import agent.dbgeng.manager.DbgCause.Causes;
import agent.dbgeng.manager.DbgManager;
import agent.dbgeng.manager.impl.DbgManagerImpl;
import agent.dbgeng.manager.impl.DbgSessionImpl;
@ -51,7 +50,7 @@ public class DbgModelImpl extends AbstractDbgModel {
this.root = new DbgModelTargetRootImpl(this);
this.completedRoot = CompletableFuture.completedFuture(root);
DbgSessionImpl s = new DbgSessionImpl((DbgManagerImpl) dbg, new DebugSessionId(0));
s.add(Causes.UNCLAIMED);
s.add();
DbgModelTargetSessionContainer sessions = root.sessions;
this.session = (DbgModelTargetSessionImpl) sessions.getTargetSession(s);
}