Added SyncRoot object to BindingsBase that can be used to protect shared state in the various bindings.
This commit is contained in:
parent
043e0fec2f
commit
ddb56a1952
8 changed files with 112 additions and 7 deletions
|
@ -111,6 +111,14 @@ namespace OpenTK
|
|||
/// </remarks>
|
||||
protected abstract IntPtr GetAddress(string funcname);
|
||||
|
||||
/// <summary>
|
||||
/// Gets an object that can be used to synchronize access to the bindings implementation.
|
||||
/// </summary>
|
||||
/// <remarks>This object should be unique across bindings but consistent between bindings
|
||||
/// of the same type. For example, ES10.GL, OpenGL.GL and CL10.CL should all return
|
||||
/// unique objects, but all instances of ES10.GL should return the same object.</remarks>
|
||||
protected abstract object SyncRoot { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Internal Members
|
||||
|
@ -141,8 +149,11 @@ namespace OpenTK
|
|||
if (d != null)
|
||||
++supported;
|
||||
|
||||
lock (SyncRoot)
|
||||
{
|
||||
f.SetValue(null, d);
|
||||
}
|
||||
}
|
||||
|
||||
rebuildExtensionList = true;
|
||||
|
||||
|
@ -166,10 +177,13 @@ namespace OpenTK
|
|||
|
||||
Delegate old = f.GetValue(null) as Delegate;
|
||||
Delegate @new = LoadDelegate(f.Name, f.FieldType);
|
||||
lock (SyncRoot)
|
||||
{
|
||||
if (old.Target != @new.Target)
|
||||
{
|
||||
f.SetValue(null, @new);
|
||||
}
|
||||
}
|
||||
return @new != null;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,11 +35,12 @@ namespace OpenTK.Compute.CL10
|
|||
/// <summary>
|
||||
/// Provides access to the OpenCL 1.0 flat API.
|
||||
/// </summary>
|
||||
public partial class CL
|
||||
public partial class CL : BindingsBase
|
||||
{
|
||||
#region Private Members
|
||||
#region Fields
|
||||
|
||||
const string Library = "opencl.dll";
|
||||
static readonly object sync_root = new object();
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -61,5 +62,35 @@ namespace OpenTK.Compute.CL10
|
|||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Protected Members
|
||||
|
||||
/// <summary>
|
||||
/// Returns a synchronization token unique for the GL class.
|
||||
/// </summary>
|
||||
protected override object SyncRoot
|
||||
{
|
||||
get { return sync_root; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Not supported yet.
|
||||
/// </summary>
|
||||
/// <param name="funcname">The name of the extension function.</param>
|
||||
/// <returns>A pointer to the extension function, if available; IntPtr.Zero otherwise.</returns>
|
||||
/// <remarks>
|
||||
/// <para>Use <see cref="Marshal.GetDelegateForFunctionPointer"/> to turn this function pointer
|
||||
/// into a callable delegate.</para>
|
||||
/// <para>A non-zero return value does not mean that this extension function is supported. You also
|
||||
/// need to query available extensions through <see cref="GetDeviceInfo"/>.</para>
|
||||
/// <para>This method will always return IntPtr.Zero for core (i.e. non-extension) functions.</para>
|
||||
/// </remarks>
|
||||
protected override IntPtr GetAddress(string funcname)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
//CL.GetExtensionFunctionAddress
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,5 +10,19 @@ namespace OpenTK.Graphics.ES10
|
|||
public sealed partial class GL : GraphicsBindingsBase
|
||||
{
|
||||
const string Library = "libGLES.dll";
|
||||
static readonly object sync_root = new object();
|
||||
|
||||
#region --- Protected Members ---
|
||||
|
||||
/// <summary>
|
||||
/// Returns a synchronization token unique for the GL class.
|
||||
/// </summary>
|
||||
protected override object SyncRoot
|
||||
{
|
||||
get { return sync_root; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,5 +12,19 @@ namespace OpenTK.Graphics.ES11
|
|||
public sealed partial class GL : GraphicsBindingsBase
|
||||
{
|
||||
const string Library = "libGLES.dll";
|
||||
static readonly object sync_root = new object();
|
||||
|
||||
#region --- Protected Members ---
|
||||
|
||||
/// <summary>
|
||||
/// Returns a synchronization token unique for the GL class.
|
||||
/// </summary>
|
||||
protected override object SyncRoot
|
||||
{
|
||||
get { return sync_root; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,6 +37,19 @@ namespace OpenTK.Graphics.ES20
|
|||
public sealed partial class GL : GraphicsBindingsBase
|
||||
{
|
||||
const string Library = "libGLESv2.dll";
|
||||
static readonly object sync_root = new object();
|
||||
|
||||
#region --- Protected Members ---
|
||||
|
||||
/// <summary>
|
||||
/// Returns a synchronization token unique for the GL class.
|
||||
/// </summary>
|
||||
protected override object SyncRoot
|
||||
{
|
||||
get { return sync_root; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helper Overloads
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ namespace OpenTK.Graphics
|
|||
/// <summary>
|
||||
/// Implements BindingsBase for the OpenTK.Graphics namespace (OpenGL and OpenGL|ES).
|
||||
/// </summary>
|
||||
public class GraphicsBindingsBase : BindingsBase
|
||||
public abstract class GraphicsBindingsBase : BindingsBase
|
||||
{
|
||||
/// <summary>
|
||||
/// Retrieves an unmanaged function pointer to the specified function.
|
||||
|
|
|
@ -52,7 +52,8 @@ namespace OpenTK.Graphics.OpenGL
|
|||
|
||||
internal const string Library = "opengl32.dll";
|
||||
|
||||
private static SortedList<string, bool> AvailableExtensions = new SortedList<string, bool>();
|
||||
static SortedList<string, bool> AvailableExtensions = new SortedList<string, bool>();
|
||||
static readonly object sync_root = new object();
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -335,6 +336,18 @@ namespace OpenTK.Graphics.OpenGL
|
|||
#endif
|
||||
#endregion
|
||||
|
||||
#region --- Protected Members ---
|
||||
|
||||
/// <summary>
|
||||
/// Returns a synchronization token unique for the GL class.
|
||||
/// </summary>
|
||||
protected override object SyncRoot
|
||||
{
|
||||
get { return sync_root; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region --- GL Overloads ---
|
||||
|
||||
#pragma warning disable 3019
|
||||
|
|
|
@ -18,10 +18,16 @@ namespace OpenTK.Platform.X11
|
|||
partial class Glx : BindingsBase
|
||||
{
|
||||
const string Library = "libGL.so.1";
|
||||
static readonly object sync_root = new object();
|
||||
|
||||
// Disable BeforeFieldInit optimization.
|
||||
static Glx() { }
|
||||
|
||||
protected override object SyncRoot
|
||||
{
|
||||
get { return sync_root; }
|
||||
}
|
||||
|
||||
protected override IntPtr GetAddress (string funcname)
|
||||
{
|
||||
return Glx.GetProcAddress(funcname);
|
||||
|
|
Loading…
Reference in a new issue