mirror of
https://github.com/goatcorp/Dalamud.git
synced 2025-12-12 18:27:23 +01:00
chore: Obsolete accessing ObjectTable off main thread
This commit is contained in:
parent
6a1cea731f
commit
c3df199e29
1 changed files with 7 additions and 35 deletions
|
|
@ -66,7 +66,7 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
_ = this.WarnMultithreadedUsage();
|
ThreadSafety.AssertMainThread();
|
||||||
|
|
||||||
return (nint)(&CSGameObjectManager.Instance()->Objects);
|
return (nint)(&CSGameObjectManager.Instance()->Objects);
|
||||||
}
|
}
|
||||||
|
|
@ -80,7 +80,7 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
_ = this.WarnMultithreadedUsage();
|
ThreadSafety.AssertMainThread();
|
||||||
|
|
||||||
return (index >= objectTableLength || index < 0) ? null : this.cachedObjectTable[index].Update();
|
return (index >= objectTableLength || index < 0) ? null : this.cachedObjectTable[index].Update();
|
||||||
}
|
}
|
||||||
|
|
@ -89,7 +89,7 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IGameObject? SearchById(ulong gameObjectId)
|
public IGameObject? SearchById(ulong gameObjectId)
|
||||||
{
|
{
|
||||||
_ = this.WarnMultithreadedUsage();
|
ThreadSafety.AssertMainThread();
|
||||||
|
|
||||||
if (gameObjectId is 0)
|
if (gameObjectId is 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -106,7 +106,7 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IGameObject? SearchByEntityId(uint entityId)
|
public IGameObject? SearchByEntityId(uint entityId)
|
||||||
{
|
{
|
||||||
_ = this.WarnMultithreadedUsage();
|
ThreadSafety.AssertMainThread();
|
||||||
|
|
||||||
if (entityId is 0 or 0xE0000000)
|
if (entityId is 0 or 0xE0000000)
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -123,7 +123,7 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public unsafe nint GetObjectAddress(int index)
|
public unsafe nint GetObjectAddress(int index)
|
||||||
{
|
{
|
||||||
_ = this.WarnMultithreadedUsage();
|
ThreadSafety.AssertMainThread();
|
||||||
|
|
||||||
return (index >= objectTableLength || index < 0) ? nint.Zero : (nint)this.cachedObjectTable[index].Address;
|
return (index >= objectTableLength || index < 0) ? nint.Zero : (nint)this.cachedObjectTable[index].Address;
|
||||||
}
|
}
|
||||||
|
|
@ -131,7 +131,7 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public unsafe IGameObject? CreateObjectReference(nint address)
|
public unsafe IGameObject? CreateObjectReference(nint address)
|
||||||
{
|
{
|
||||||
_ = this.WarnMultithreadedUsage();
|
ThreadSafety.AssertMainThread();
|
||||||
|
|
||||||
if (this.clientState.LocalContentId == 0)
|
if (this.clientState.LocalContentId == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -155,27 +155,6 @@ internal sealed partial class ObjectTable : IServiceType, IObjectTable
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
[Api12ToDo("Use ThreadSafety.AssertMainThread() instead of this.")]
|
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
||||||
private bool WarnMultithreadedUsage()
|
|
||||||
{
|
|
||||||
if (ThreadSafety.IsMainThread)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
var n = Environment.TickCount64;
|
|
||||||
if (this.nextMultithreadedUsageWarnTime < n)
|
|
||||||
{
|
|
||||||
this.nextMultithreadedUsageWarnTime = n + 30000;
|
|
||||||
|
|
||||||
Log.Warning(
|
|
||||||
"{plugin} is accessing {objectTable} outside the main thread. This is deprecated.",
|
|
||||||
Service<PluginManager>.Get().FindCallingPlugin()?.Name ?? "<unknown plugin>",
|
|
||||||
nameof(ObjectTable));
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>Stores an object table entry, with preallocated concrete types.</summary>
|
/// <summary>Stores an object table entry, with preallocated concrete types.</summary>
|
||||||
/// <remarks>Initializes a new instance of the <see cref="CachedEntry"/> struct.</remarks>
|
/// <remarks>Initializes a new instance of the <see cref="CachedEntry"/> struct.</remarks>
|
||||||
/// <param name="gameObjectPtr">A pointer to the object table entry this entry should be pointing to.</param>
|
/// <param name="gameObjectPtr">A pointer to the object table entry this entry should be pointing to.</param>
|
||||||
|
|
@ -228,14 +207,7 @@ internal sealed partial class ObjectTable
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public IEnumerator<IGameObject> GetEnumerator()
|
public IEnumerator<IGameObject> GetEnumerator()
|
||||||
{
|
{
|
||||||
// If something's trying to enumerate outside the framework thread, we use the ObjectPool.
|
ThreadSafety.AssertMainThread();
|
||||||
if (this.WarnMultithreadedUsage())
|
|
||||||
{
|
|
||||||
// let's not
|
|
||||||
var e = this.multiThreadedEnumerators.Get();
|
|
||||||
e.InitializeForPooledObjects(this);
|
|
||||||
return e;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we're on the framework thread, see if there's an already allocated enumerator available for use.
|
// If we're on the framework thread, see if there's an already allocated enumerator available for use.
|
||||||
foreach (ref var x in this.frameworkThreadEnumerators.AsSpan())
|
foreach (ref var x in this.frameworkThreadEnumerators.AsSpan())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue