Fix realm refetch operations potentially being unsafe

As seen in test failure https://github.com/ppy/osu/runs/6357384721?check_suite_focus=true.
This commit is contained in:
Dean Herbert
2022-05-10 20:47:26 +09:00
parent 87f6f74795
commit 33f024212f
2 changed files with 37 additions and 8 deletions

View File

@ -344,6 +344,26 @@ namespace osu.Game.Database
}
}
/// <summary>
/// Write changes to realm.
/// </summary>
/// <param name="action">The work to run.</param>
public T Write<T>(Func<Realm, T> action)
{
if (ThreadSafety.IsUpdateThread)
{
total_writes_update.Value++;
return Realm.Write(action);
}
else
{
total_writes_async.Value++;
using (var realm = getRealmInstance())
return realm.Write(action);
}
}
/// <summary>
/// Write changes to realm.
/// </summary>