mirror of
https://github.com/Ryujinx/GtkSharp.git
synced 2024-12-22 20:35:37 +00:00
Cleanup of sourceproxy Dictionary and its usages
This commit is contained in:
parent
6af04a1058
commit
cd47acba85
|
@ -10,7 +10,7 @@
|
|||
// Copyright (c) 2009 Novell, Inc.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
|
@ -64,14 +64,14 @@ namespace GLib {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Idle ()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
delegate uint d_g_idle_add(IdleHandlerInternal d, IntPtr data);
|
||||
static d_g_idle_add g_idle_add = FuncLoader.LoadFunction<d_g_idle_add>(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_idle_add"));
|
||||
delegate uint d_g_idle_add_full(int priority, IdleHandlerInternal d, IntPtr data, DestroyNotify notify);
|
||||
static d_g_idle_add_full g_idle_add_full = FuncLoader.LoadFunction<d_g_idle_add_full>(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_idle_add_full"));
|
||||
|
||||
public static uint Add (IdleHandler hndlr)
|
||||
{
|
||||
|
@ -81,36 +81,15 @@ namespace GLib {
|
|||
var gch = GCHandle.Alloc(p);
|
||||
var userData = GCHandle.ToIntPtr(gch);
|
||||
p.ID = g_idle_add_full (0, (IdleHandlerInternal) p.proxy_handler, userData, DestroyHelper.NotifyHandler);
|
||||
Source.AddSourceHandler (p.ID, p);
|
||||
}
|
||||
|
||||
return p.ID;
|
||||
}
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
delegate uint d_g_idle_add_full(int priority, IdleHandlerInternal d, IntPtr data, DestroyNotify notify);
|
||||
static d_g_idle_add_full g_idle_add_full = FuncLoader.LoadFunction<d_g_idle_add_full>(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_idle_add_full"));
|
||||
|
||||
public static uint Add (IdleHandler hndlr, Priority priority)
|
||||
{
|
||||
IdleProxy p = new IdleProxy (hndlr);
|
||||
lock (p)
|
||||
{
|
||||
p.ID = g_idle_add_full ((int)priority, (IdleHandlerInternal)p.proxy_handler, IntPtr.Zero, null);
|
||||
Source.AddSourceHandler (p.ID, p);
|
||||
}
|
||||
|
||||
return p.ID;
|
||||
}
|
||||
|
||||
public static void Remove (uint id)
|
||||
{
|
||||
Source.Remove (id);
|
||||
}
|
||||
|
||||
public static bool Remove (IdleHandler hndlr)
|
||||
{
|
||||
return Source.RemoveSourceHandler (hndlr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
// Copyright (c) 2002 Mike Kestner
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
|
@ -62,7 +62,6 @@ namespace GLib {
|
|||
|
||||
internal void Remove ()
|
||||
{
|
||||
Source.RemoveSourceHandler (ID);
|
||||
real_handler = null;
|
||||
proxy_handler = null;
|
||||
}
|
||||
|
@ -70,8 +69,6 @@ namespace GLib {
|
|||
|
||||
public partial class Source : GLib.Opaque {
|
||||
|
||||
private static IDictionary<uint, SourceProxy> source_handlers = new Dictionary<uint, SourceProxy> ();
|
||||
|
||||
private Source () {}
|
||||
|
||||
public Source(IntPtr raw) : base(raw) {}
|
||||
|
@ -110,57 +107,13 @@ namespace GLib {
|
|||
GLib.Timeout.Add (50, new GLib.TimeoutHandler (info.Handler));
|
||||
}
|
||||
|
||||
internal static void AddSourceHandler (uint id, SourceProxy proxy)
|
||||
{
|
||||
lock (Source.source_handlers) {
|
||||
source_handlers [id] = proxy;
|
||||
}
|
||||
}
|
||||
|
||||
internal static void RemoveSourceHandler (uint id)
|
||||
{
|
||||
lock (Source.source_handlers) {
|
||||
source_handlers.Remove (id);
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool RemoveSourceHandler (Delegate hndlr)
|
||||
{
|
||||
bool result = false;
|
||||
List<uint> keys = new List<uint> ();
|
||||
|
||||
lock (source_handlers) {
|
||||
foreach (uint code in source_handlers.Keys) {
|
||||
var p = Source.source_handlers [code];
|
||||
|
||||
if (p != null && p.real_handler == hndlr) {
|
||||
keys.Add (code);
|
||||
result = g_source_remove (code);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var key in keys) {
|
||||
Source.RemoveSourceHandler (key);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
delegate bool d_g_source_remove(uint tag);
|
||||
static d_g_source_remove g_source_remove = FuncLoader.LoadFunction<d_g_source_remove>(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_source_remove"));
|
||||
|
||||
public static bool Remove (uint tag)
|
||||
{
|
||||
// g_source_remove always returns true, so we follow that
|
||||
bool ret = true;
|
||||
|
||||
lock (Source.source_handlers) {
|
||||
if (source_handlers.Remove (tag)) {
|
||||
ret = g_source_remove (tag);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
return g_source_remove (tag);
|
||||
}
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
delegate IntPtr d_g_source_get_type();
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
// Copyright (c) 2009 Novell, Inc.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
|
@ -62,12 +62,12 @@ namespace GLib {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private Timeout () {}
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
delegate uint d_g_timeout_add(uint interval, TimeoutHandlerInternal d, IntPtr data);
|
||||
static d_g_timeout_add g_timeout_add = FuncLoader.LoadFunction<d_g_timeout_add>(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_timeout_add"));
|
||||
|
||||
private Timeout () {}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
delegate uint d_g_timeout_add_full(int priority, uint interval, TimeoutHandlerInternal d, IntPtr data, DestroyNotify notify);
|
||||
static d_g_timeout_add_full g_timeout_add_full = FuncLoader.LoadFunction<d_g_timeout_add_full>(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_timeout_add_full"));
|
||||
public static uint Add (uint interval, TimeoutHandler hndlr)
|
||||
{
|
||||
TimeoutProxy p = new TimeoutProxy (hndlr);
|
||||
|
@ -76,37 +76,36 @@ namespace GLib {
|
|||
var gch = GCHandle.Alloc(p);
|
||||
var userData = GCHandle.ToIntPtr(gch);
|
||||
p.ID = g_timeout_add_full (0, interval, (TimeoutHandlerInternal) p.proxy_handler, userData, DestroyHelper.NotifyHandler);
|
||||
Source.AddSourceHandler (p.ID, p);
|
||||
}
|
||||
|
||||
return p.ID;
|
||||
}
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
delegate uint d_g_timeout_add_full(int priority, uint interval, TimeoutHandlerInternal d, IntPtr data, DestroyNotify notify);
|
||||
static d_g_timeout_add_full g_timeout_add_full = FuncLoader.LoadFunction<d_g_timeout_add_full>(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_timeout_add_full"));
|
||||
|
||||
public static uint Add (uint interval, TimeoutHandler hndlr, Priority priority)
|
||||
{
|
||||
TimeoutProxy p = new TimeoutProxy (hndlr);
|
||||
lock (p)
|
||||
{
|
||||
var gch = GCHandle.Alloc(p);
|
||||
var userData = GCHandle.ToIntPtr(gch);
|
||||
p.ID = g_timeout_add_full ((int)priority, interval, (TimeoutHandlerInternal) p.proxy_handler, IntPtr.Zero, null);
|
||||
Source.AddSourceHandler (p.ID, p);
|
||||
}
|
||||
|
||||
return p.ID;
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
delegate uint d_g_timeout_add_seconds(uint interval, TimeoutHandlerInternal d, IntPtr data);
|
||||
static d_g_timeout_add_seconds g_timeout_add_seconds = FuncLoader.LoadFunction<d_g_timeout_add_seconds>(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_timeout_add_seconds"));
|
||||
delegate uint d_g_timeout_add_seconds_full(int priority, uint interval, TimeoutHandlerInternal d, IntPtr data, DestroyNotify notify);
|
||||
static d_g_timeout_add_seconds_full g_timeout_add_seconds_full = FuncLoader.LoadFunction<d_g_timeout_add_seconds_full>(FuncLoader.GetProcAddress(GLibrary.Load(Library.GLib), "g_timeout_add_seconds_full"));
|
||||
|
||||
public static uint AddSeconds (uint interval, TimeoutHandler hndlr)
|
||||
{
|
||||
TimeoutProxy p = new TimeoutProxy (hndlr);
|
||||
lock (p)
|
||||
{
|
||||
p.ID = g_timeout_add_seconds (interval, (TimeoutHandlerInternal) p.proxy_handler, IntPtr.Zero);
|
||||
Source.AddSourceHandler (p.ID, p);
|
||||
var gch = GCHandle.Alloc(p);
|
||||
var userData = GCHandle.ToIntPtr(gch);
|
||||
p.ID = g_timeout_add_seconds_full (0, interval, (TimeoutHandlerInternal) p.proxy_handler, userData, DestroyHelper.NotifyHandler);
|
||||
}
|
||||
|
||||
return p.ID;
|
||||
|
@ -116,11 +115,6 @@ namespace GLib {
|
|||
{
|
||||
Source.Remove (id);
|
||||
}
|
||||
|
||||
public static bool Remove (TimeoutHandler hndlr)
|
||||
{
|
||||
return Source.RemoveSourceHandler (hndlr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue