mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2025-02-02 15:41:00 +00:00
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:
parent
9abde602ec
commit
8b101d5525
10
glib/Cond.cs
10
glib/Cond.cs
|
@ -43,21 +43,15 @@ namespace GLib {
|
||||||
static extern void g_cond_wait(IntPtr raw, IntPtr mutex);
|
static extern void g_cond_wait(IntPtr raw, IntPtr mutex);
|
||||||
|
|
||||||
public void Wait(GLib.Mutex mutex) {
|
public void Wait(GLib.Mutex mutex) {
|
||||||
IntPtr native_mutex = GLib.Marshaller.StructureToPtrAlloc (mutex);
|
g_cond_wait(Handle, mutex == null ? IntPtr.Zero : mutex.Handle);
|
||||||
g_cond_wait(Handle, native_mutex);
|
|
||||||
mutex = GLib.Mutex.New (native_mutex);
|
|
||||||
Marshal.FreeHGlobal (native_mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern bool g_cond_wait_until(IntPtr raw, IntPtr mutex, long end_time);
|
static extern bool g_cond_wait_until(IntPtr raw, IntPtr mutex, long end_time);
|
||||||
|
|
||||||
public bool WaitUntil(GLib.Mutex 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, mutex == null ? IntPtr.Zero : mutex.Handle, end_time);
|
||||||
bool raw_ret = g_cond_wait_until(Handle, native_mutex, end_time);
|
|
||||||
bool ret = raw_ret;
|
bool ret = raw_ret;
|
||||||
mutex = GLib.Mutex.New (native_mutex);
|
|
||||||
Marshal.FreeHGlobal (native_mutex);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,6 +21,8 @@ references =
|
||||||
|
|
||||||
# TODO: auto-generate at compile time the following classes:
|
# TODO: auto-generate at compile time the following classes:
|
||||||
# Cond, Date, DateTime, Mutex, RecMutex, TimeVal, TimeZone
|
# Cond, Date, DateTime, Mutex, RecMutex, TimeVal, TimeZone
|
||||||
|
# (to do that, we need to fill missing pieces in glib's
|
||||||
|
# gobject-introspection metadata upstream)
|
||||||
|
|
||||||
sources = \
|
sources = \
|
||||||
Argv.cs \
|
Argv.cs \
|
||||||
|
|
|
@ -9,66 +9,35 @@ namespace GLib {
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
#region Autogenerated code
|
#region Autogenerated code
|
||||||
[StructLayout(LayoutKind.Explicit)]
|
public partial class Mutex : GLib.Opaque {
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern void g_mutex_clear(IntPtr raw);
|
static extern void g_mutex_clear(IntPtr raw);
|
||||||
|
|
||||||
public void Clear() {
|
public void Clear() {
|
||||||
IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
|
g_mutex_clear(Handle);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern void g_mutex_init(IntPtr raw);
|
static extern void g_mutex_init(IntPtr raw);
|
||||||
|
|
||||||
public void Init() {
|
public void Init() {
|
||||||
IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
|
g_mutex_init(Handle);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern void g_mutex_lock(IntPtr raw);
|
static extern void g_mutex_lock(IntPtr raw);
|
||||||
|
|
||||||
public void Lock() {
|
public void Lock() {
|
||||||
IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
|
g_mutex_lock(Handle);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
[DllImport("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
||||||
static extern bool g_mutex_trylock(IntPtr raw);
|
static extern bool g_mutex_trylock(IntPtr raw);
|
||||||
|
|
||||||
public bool Trylock() {
|
public bool Trylock() {
|
||||||
IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
|
bool raw_ret = g_mutex_trylock(Handle);
|
||||||
System.Runtime.InteropServices.Marshal.StructureToPtr (this, this_as_native, false);
|
|
||||||
bool raw_ret = g_mutex_trylock(this_as_native);
|
|
||||||
bool ret = raw_ret;
|
bool ret = raw_ret;
|
||||||
ReadNative (this_as_native, ref this);
|
|
||||||
System.Runtime.InteropServices.Marshal.FreeHGlobal (this_as_native);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,32 +45,10 @@ namespace GLib {
|
||||||
static extern void g_mutex_unlock(IntPtr raw);
|
static extern void g_mutex_unlock(IntPtr raw);
|
||||||
|
|
||||||
public void Unlock() {
|
public void Unlock() {
|
||||||
IntPtr this_as_native = System.Runtime.InteropServices.Marshal.AllocHGlobal (System.Runtime.InteropServices.Marshal.SizeOf (this));
|
g_mutex_unlock(Handle);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ReadNative (IntPtr native, ref GLib.Mutex target)
|
public Mutex(IntPtr raw) : base(raw) {}
|
||||||
{
|
|
||||||
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 ();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue