diff --git a/Source/OpenTK/BindingsBase.cs b/Source/OpenTK/BindingsBase.cs
index d1a521dc..4c968a65 100644
--- a/Source/OpenTK/BindingsBase.cs
+++ b/Source/OpenTK/BindingsBase.cs
@@ -111,6 +111,14 @@ namespace OpenTK
///
protected abstract IntPtr GetAddress(string funcname);
+ ///
+ /// Gets an object that can be used to synchronize access to the bindings implementation.
+ ///
+ /// 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.
+ protected abstract object SyncRoot { get; }
+
#endregion
#region Internal Members
@@ -141,7 +149,10 @@ namespace OpenTK
if (d != null)
++supported;
- f.SetValue(null, d);
+ lock (SyncRoot)
+ {
+ f.SetValue(null, d);
+ }
}
rebuildExtensionList = true;
@@ -166,9 +177,12 @@ namespace OpenTK
Delegate old = f.GetValue(null) as Delegate;
Delegate @new = LoadDelegate(f.Name, f.FieldType);
- if (old.Target != @new.Target)
+ lock (SyncRoot)
{
- f.SetValue(null, @new);
+ if (old.Target != @new.Target)
+ {
+ f.SetValue(null, @new);
+ }
}
return @new != null;
}
diff --git a/Source/OpenTK/Compute/CL10/CLHelper.cs b/Source/OpenTK/Compute/CL10/CLHelper.cs
index 4c94b65a..22e488fa 100644
--- a/Source/OpenTK/Compute/CL10/CLHelper.cs
+++ b/Source/OpenTK/Compute/CL10/CLHelper.cs
@@ -35,11 +35,12 @@ namespace OpenTK.Compute.CL10
///
/// Provides access to the OpenCL 1.0 flat API.
///
- 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
+
+ ///
+ /// Returns a synchronization token unique for the GL class.
+ ///
+ protected override object SyncRoot
+ {
+ get { return sync_root; }
+ }
+
+ ///
+ /// Not supported yet.
+ ///
+ /// The name of the extension function.
+ /// A pointer to the extension function, if available; IntPtr.Zero otherwise.
+ ///
+ /// Use to turn this function pointer
+ /// into a callable delegate.
+ /// A non-zero return value does not mean that this extension function is supported. You also
+ /// need to query available extensions through .
+ /// This method will always return IntPtr.Zero for core (i.e. non-extension) functions.
+ ///
+ protected override IntPtr GetAddress(string funcname)
+ {
+ throw new NotSupportedException();
+ //CL.GetExtensionFunctionAddress
+ }
+
+ #endregion
}
}
diff --git a/Source/OpenTK/Graphics/ES10/Helper.cs b/Source/OpenTK/Graphics/ES10/Helper.cs
index da2d4947..16f87c7c 100644
--- a/Source/OpenTK/Graphics/ES10/Helper.cs
+++ b/Source/OpenTK/Graphics/ES10/Helper.cs
@@ -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 ---
+
+ ///
+ /// Returns a synchronization token unique for the GL class.
+ ///
+ protected override object SyncRoot
+ {
+ get { return sync_root; }
+ }
+
+ #endregion
+
}
}
diff --git a/Source/OpenTK/Graphics/ES11/Helper.cs b/Source/OpenTK/Graphics/ES11/Helper.cs
index eab6d123..49917848 100644
--- a/Source/OpenTK/Graphics/ES11/Helper.cs
+++ b/Source/OpenTK/Graphics/ES11/Helper.cs
@@ -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 ---
+
+ ///
+ /// Returns a synchronization token unique for the GL class.
+ ///
+ protected override object SyncRoot
+ {
+ get { return sync_root; }
+ }
+
+ #endregion
+
}
}
diff --git a/Source/OpenTK/Graphics/ES20/Helper.cs b/Source/OpenTK/Graphics/ES20/Helper.cs
index 78c9ae4f..4fdd6697 100644
--- a/Source/OpenTK/Graphics/ES20/Helper.cs
+++ b/Source/OpenTK/Graphics/ES20/Helper.cs
@@ -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 ---
+
+ ///
+ /// Returns a synchronization token unique for the GL class.
+ ///
+ protected override object SyncRoot
+ {
+ get { return sync_root; }
+ }
+
+ #endregion
#region Helper Overloads
diff --git a/Source/OpenTK/Graphics/GraphicsBindingsBase.cs b/Source/OpenTK/Graphics/GraphicsBindingsBase.cs
index cf5cd204..8ca5997e 100644
--- a/Source/OpenTK/Graphics/GraphicsBindingsBase.cs
+++ b/Source/OpenTK/Graphics/GraphicsBindingsBase.cs
@@ -32,7 +32,7 @@ namespace OpenTK.Graphics
///
/// Implements BindingsBase for the OpenTK.Graphics namespace (OpenGL and OpenGL|ES).
///
- public class GraphicsBindingsBase : BindingsBase
+ public abstract class GraphicsBindingsBase : BindingsBase
{
///
/// Retrieves an unmanaged function pointer to the specified function.
diff --git a/Source/OpenTK/Graphics/OpenGL/GLHelper.cs b/Source/OpenTK/Graphics/OpenGL/GLHelper.cs
index fe392a89..af8421b1 100644
--- a/Source/OpenTK/Graphics/OpenGL/GLHelper.cs
+++ b/Source/OpenTK/Graphics/OpenGL/GLHelper.cs
@@ -52,7 +52,8 @@ namespace OpenTK.Graphics.OpenGL
internal const string Library = "opengl32.dll";
- private static SortedList AvailableExtensions = new SortedList();
+ static SortedList AvailableExtensions = new SortedList();
+ static readonly object sync_root = new object();
#endregion
@@ -335,6 +336,18 @@ namespace OpenTK.Graphics.OpenGL
#endif
#endregion
+ #region --- Protected Members ---
+
+ ///
+ /// Returns a synchronization token unique for the GL class.
+ ///
+ protected override object SyncRoot
+ {
+ get { return sync_root; }
+ }
+
+ #endregion
+
#region --- GL Overloads ---
#pragma warning disable 3019
diff --git a/Source/OpenTK/Platform/X11/GlxHelper.cs b/Source/OpenTK/Platform/X11/GlxHelper.cs
index 2094509b..3ec38c1b 100644
--- a/Source/OpenTK/Platform/X11/GlxHelper.cs
+++ b/Source/OpenTK/Platform/X11/GlxHelper.cs
@@ -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);