Files
OpenRA/OpenRA.Platforms.Default/ThreadAffine.cs
RoosterDragon fc436f1aab Added thread-affinity checks to SDL2 renderer.
If a call is made into a graphics resource that has thread-affinity, from a thread other than the one that created the graphics device, an exception will now be thrown to make debugging easier.
2015-09-18 21:04:21 +01:00

32 lines
850 B
C#

#region Copyright & License Information
/*
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Threading;
namespace OpenRA.Platforms.Default
{
abstract class ThreadAffine
{
readonly int managedThreadId;
protected ThreadAffine()
{
managedThreadId = Thread.CurrentThread.ManagedThreadId;
}
protected void VerifyThreadAffinity()
{
if (managedThreadId != Thread.CurrentThread.ManagedThreadId)
throw new InvalidOperationException("Cross-thread operation not valid: This method must be called from the same thread that created this object.");
}
}
}