fix thread safety for ecsdebug

This commit is contained in:
Mikhail 2024-09-10 19:18:46 +08:00
parent 7cf6894476
commit f2ffc284f9

View File

@ -123,22 +123,31 @@ namespace DCFApixels.DragonECS
get get
{ {
if (_instance == null) if (_instance == null)
{
lock (_lock)
{ {
_instance = new DefaultDebugService(); _instance = new DefaultDebugService();
} }
}
return _instance; return _instance;
} }
} }
public static void Set<T>() where T : DebugService, new() public static void Set<T>() where T : DebugService, new()
{
lock (_lock)
{ {
Set(new T()); Set(new T());
} }
}
public static void Set(DebugService service) public static void Set(DebugService service)
{
lock (_lock)
{ {
_instance = service; _instance = service;
OnServiceChanged(_instance); OnServiceChanged(_instance);
} }
}
public static Action<DebugService> OnServiceChanged = delegate { }; public static Action<DebugService> OnServiceChanged = delegate { };
@ -161,13 +170,16 @@ namespace DCFApixels.DragonECS
return id; return id;
} }
public void DeleteMark(string name) public void DeleteMark(string name)
{
lock (_lock)
{ {
int id = _nameIdTable[name]; int id = _nameIdTable[name];
//TODO кажется этот TryRemove не подходит //TODO проверить TryRemove
_nameIdTable.TryRemove(name, out id); _nameIdTable.TryRemove(name, out id);
_idDispenser.Release(id); _idDispenser.Release(id);
OnDelProfilerMark(id); OnDelProfilerMark(id);
} }
}
protected abstract void OnNewProfilerMark(int id, string name); protected abstract void OnNewProfilerMark(int id, string name);
protected abstract void OnDelProfilerMark(int id); protected abstract void OnDelProfilerMark(int id);