glib: Mutex is actually opaque

This means that we're modifying the generated code that
we checked in, so then we increase the future TODO about
more information about what we need to fix later.

The changes to Cond are a consequence of the changes to
Mutex because the former uses the latter.
This commit is contained in:
Stephan Sundermann 2013-10-09 18:44:04 +02:00 committed by Andrés G. Aragoneses
parent 9abde602ec
commit 8b101d5525
3 changed files with 11 additions and 68 deletions

View file

@ -43,21 +43,15 @@ namespace GLib {
static extern void g_cond_wait(IntPtr raw, IntPtr mutex);
public void Wait(GLib.Mutex mutex) {
IntPtr native_mutex = GLib.Marshaller.StructureToPtrAlloc (mutex);
g_cond_wait(Handle, native_mutex);
mutex = GLib.Mutex.New (native_mutex);
Marshal.FreeHGlobal (native_mutex);
g_cond_wait(Handle, mutex == null ? IntPtr.Zero : mutex.Handle);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern bool g_cond_wait_until(IntPtr raw, IntPtr mutex, long end_time);
public bool WaitUntil(GLib.Mutex mutex, long end_time) {
IntPtr native_mutex = GLib.Marshaller.StructureToPtrAlloc (mutex);
bool raw_ret = g_cond_wait_until(Handle, native_mutex, end_time);
bool raw_ret = g_cond_wait_until(Handle, mutex == null ? IntPtr.Zero : mutex.Handle, end_time);
bool ret = raw_ret;
mutex = GLib.Mutex.New (native_mutex);
Marshal.FreeHGlobal (native_mutex);
return ret;
}

View file

@ -21,6 +21,8 @@ references =
# TODO: auto-generate at compile time the following classes:
# Cond, Date, DateTime, Mutex, RecMutex, TimeVal, TimeZone
# (to do that, we need to fill missing pieces in glib's
# gobject-introspection metadata upstream)
sources = \
Argv.cs \

View file

@ -9,66 +9,35 @@ namespace GLib {
using System.Runtime.InteropServices;
#region Autogenerated code
[StructLayout(LayoutKind.Explicit)]
public partial struct Mutex : IEquatable<Mutex> {
[FieldOffset(0)]
private IntPtr _p;
[FieldOffset(0)]
[MarshalAs (UnmanagedType.ByValArray, SizeConst=2)]
public uint[] I;
public static GLib.Mutex Zero = new GLib.Mutex ();
public static GLib.Mutex New(IntPtr raw) {
if (raw == IntPtr.Zero)
return GLib.Mutex.Zero;
return (GLib.Mutex) Marshal.PtrToStructure (raw, typeof (GLib.Mutex));
}
public partial class Mutex : GLib.Opaque {
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_mutex_clear(IntPtr raw);
public void Clear() {
IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
g_mutex_clear(this_as_native);
ReadNative (this_as_native, ref this);
System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
g_mutex_clear(Handle);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_mutex_init(IntPtr raw);
public void Init() {
IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
g_mutex_init(this_as_native);
ReadNative (this_as_native, ref this);
System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
g_mutex_init(Handle);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern void g_mutex_lock(IntPtr raw);
public void Lock() {
IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
g_mutex_lock(this_as_native);
ReadNative (this_as_native, ref this);
System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
g_mutex_lock(Handle);
}
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
static extern bool g_mutex_trylock(IntPtr raw);
public bool Trylock() {
IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
bool raw_ret = g_mutex_trylock(this_as_native);
bool raw_ret = g_mutex_trylock(Handle);
bool ret = raw_ret;
ReadNative (this_as_native, ref this);
System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
return ret;
}
@ -76,32 +45,10 @@ namespace GLib {
static extern void g_mutex_unlock(IntPtr raw);
public void Unlock() {
IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
g_mutex_unlock(this_as_native);
ReadNative (this_as_native, ref this);
System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
g_mutex_unlock(Handle);
}
static void ReadNative (IntPtr native, ref GLib.Mutex target)
{
target = New (native);
}
public bool Equals (Mutex other)
{
return true && _p.Equals (other._p) && I.Equals (other.I);
}
public override bool Equals (object other)
{
return other is Mutex && Equals ((Mutex) other);
}
public override int GetHashCode ()
{
return this.GetType().FullName.GetHashCode() ^ _p.GetHashCode () ^ I.GetHashCode ();
}
public Mutex(IntPtr raw) : base(raw) {}
#endregion
}