[glib] Remove !g_thread_supported() codepaths in gio
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib] Remove !g_thread_supported() codepaths in gio
- Date: Fri, 9 Sep 2011 17:09:14 +0000 (UTC)
commit 5a30712dc7e4adc36b0e8fd82cf5ccec19bbbdc5
Author: Dan Winship <danw gnome org>
Date: Wed Aug 31 14:33:33 2011 -0400
Remove !g_thread_supported() codepaths in gio
In particular, remove the libasyncns import, which was only used by
GUnixResolver, which is only used when threads are not available.
Likewise remove GWin32Resolver, and the hacky broken non-threaded
parts of GIOScheduler.
https://bugzilla.gnome.org/show_bug.cgi?id=616754
configure.ac | 5 -
gio/Makefile.am | 10 +-
gio/gcancellable.c | 2 +-
gio/gio.symbols | 6 -
gio/gioscheduler.c | 60 +--
gio/gresolver.c | 18 +-
gio/gthreadedresolver.c | 8 +-
gio/gunixresolver.c | 516 ---------------
gio/gunixresolver.h | 53 --
gio/gwin32resolver.c | 483 --------------
gio/gwin32resolver.h | 49 --
gio/libasyncns/Makefile.am | 15 -
gio/libasyncns/README | 7 -
gio/libasyncns/asyncns.c | 1533 --------------------------------------------
gio/libasyncns/asyncns.h | 163 -----
gio/libasyncns/g-asyncns.h | 33 -
gio/libasyncns/update.sh | 20 -
gio/tests/resolver.c | 41 +-
18 files changed, 23 insertions(+), 2999 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 3ca84d8..91428d6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1065,11 +1065,7 @@ fi
AC_CHECK_FUNCS(getprotobyname_r endservent)
AC_CHECK_HEADERS([netdb.h wspiapi.h arpa/nameser_compat.h])
-# For gio/libasyncns
if test $glib_native_win32 = no; then
- AC_CHECK_FUNCS(strndup setresuid setreuid)
- AC_CHECK_HEADERS(sys/prctl.h)
-
# We can't just use AC_CHECK_FUNC/AC_CHECK_LIB here. Bug 586150
NETWORK_LIBS=""
AC_MSG_CHECKING([for res_query])
@@ -3842,7 +3838,6 @@ gio/gdbus-2.0/codegen/Makefile
gio/gdbus-2.0/codegen/config.py
gio/xdgmime/Makefile
gio/inotify/Makefile
-gio/libasyncns/Makefile
gio/fen/Makefile
gio/fam/Makefile
gio/win32/Makefile
diff --git a/gio/Makefile.am b/gio/Makefile.am
index 42fac22..c6eba9d 100644
--- a/gio/Makefile.am
+++ b/gio/Makefile.am
@@ -5,7 +5,7 @@ NULL =
SUBDIRS = gdbus-2.0/codegen
if OS_UNIX
-SUBDIRS += libasyncns xdgmime
+SUBDIRS += xdgmime
endif
if OS_WIN32_AND_DLL_COMPILATION
@@ -200,8 +200,8 @@ endif
if OS_UNIX
appinfo_sources += gdesktopappinfo.c
-platform_libadd += libasyncns/libasyncns.la xdgmime/libxdgmime.la
-platform_deps += libasyncns/libasyncns.la xdgmime/libxdgmime.la
+platform_libadd += xdgmime/libxdgmime.la $(RESOLVER_LIBADD)
+platform_deps += xdgmime/libxdgmime.la
unix_sources = \
gfiledescriptorbased.c \
gunixconnection.c \
@@ -211,8 +211,6 @@ unix_sources = \
gunixmount.c \
gunixmount.h \
gunixmounts.c \
- gunixresolver.c \
- gunixresolver.h \
gunixsocketaddress.c \
gunixvolume.c \
gunixvolume.h \
@@ -241,8 +239,6 @@ endif
win32_actual_sources = \
gwin32mount.c \
gwin32mount.h \
- gwin32resolver.c \
- gwin32resolver.h \
gwin32volumemonitor.c \
gwin32volumemonitor.h \
gwin32inputstream.c \
diff --git a/gio/gcancellable.c b/gio/gcancellable.c
index 6524934..15d6d0e 100644
--- a/gio/gcancellable.c
+++ b/gio/gcancellable.c
@@ -79,7 +79,7 @@ g_cancellable_class_init (GCancellableClass *klass)
g_type_class_add_private (klass, sizeof (GCancellablePrivate));
- if (cancellable_cond == NULL && g_thread_supported ())
+ if (cancellable_cond == NULL)
cancellable_cond = g_cond_new ();
gobject_class->finalize = g_cancellable_finalize;
diff --git a/gio/gio.symbols b/gio/gio.symbols
index 9451470..abe4b95 100644
--- a/gio/gio.symbols
+++ b/gio/gio.symbols
@@ -875,12 +875,6 @@ g_resolver_lookup_service
g_resolver_lookup_service_async
g_resolver_lookup_service_finish
g_threaded_resolver_get_type
-#ifdef G_OS_UNIX
-g_unix_resolver_get_type
-#endif
-#ifdef G_OS_WIN32
-g_win32_resolver_get_type
-#endif
g_srv_target_get_type
g_srv_target_new
g_srv_target_copy
diff --git a/gio/gioscheduler.c b/gio/gioscheduler.c
index 61e1afc..960f62c 100644
--- a/gio/gioscheduler.c
+++ b/gio/gioscheduler.c
@@ -32,8 +32,7 @@
* @include: gio/gio.h
*
* Schedules asynchronous I/O operations. #GIOScheduler integrates
- * into the main event loop (#GMainLoop) and may use threads if they
- * are available.
+ * into the main event loop (#GMainLoop) and uses threads.
*
* <para id="io-priority"><indexterm><primary>I/O priority</primary></indexterm>
* Each I/O operation has a priority, and the scheduler uses the priorities
@@ -55,8 +54,6 @@ struct _GIOSchedulerJob {
gint io_priority;
GCancellable *cancellable;
GMainContext *context;
-
- guint idle_tag;
};
G_LOCK_DEFINE_STATIC(active_jobs);
@@ -188,23 +185,6 @@ io_job_thread (gpointer data,
job_destroy (job);
}
-static gboolean
-run_job_at_idle (gpointer data)
-{
- GIOSchedulerJob *job = data;
- gboolean result;
-
- if (job->cancellable)
- g_cancellable_push_current (job->cancellable);
-
- result = job->job_func (job, job->cancellable, job->data);
-
- if (job->cancellable)
- g_cancellable_pop_current (job->cancellable);
-
- return result;
-}
-
/**
* g_io_scheduler_push_job:
* @job_func: a #GIOSchedulerJobFunc.
@@ -253,20 +233,8 @@ g_io_scheduler_push_job (GIOSchedulerJobFunc job_func,
job->active_link = active_jobs;
G_UNLOCK (active_jobs);
- if (g_thread_supported())
- {
- g_once (&once_init, init_scheduler, NULL);
- g_thread_pool_push (job_thread_pool, job, NULL);
- }
- else
- {
- /* Threads not available, instead do the i/o sync inside a
- * low prio idle handler
- */
- job->idle_tag = g_idle_add_full (io_priority,
- run_job_at_idle,
- job, job_destroy);
- }
+ g_once (&once_init, init_scheduler, NULL);
+ g_thread_pool_push (job_thread_pool, job, NULL);
}
/**
@@ -370,17 +338,6 @@ g_io_scheduler_job_send_to_mainloop (GIOSchedulerJob *job,
g_return_val_if_fail (job != NULL, FALSE);
g_return_val_if_fail (func != NULL, FALSE);
- if (job->idle_tag)
- {
- /* We just immediately re-enter in the case of idles (non-threads)
- * Anything else would just deadlock. If you can't handle this, enable threads.
- */
- ret_val = func (user_data);
- if (notify)
- notify (user_data);
- return ret_val;
- }
-
proxy = g_new0 (MainLoopProxy, 1);
proxy->func = func;
proxy->data = user_data;
@@ -435,17 +392,6 @@ g_io_scheduler_job_send_to_mainloop_async (GIOSchedulerJob *job,
g_return_if_fail (job != NULL);
g_return_if_fail (func != NULL);
- if (job->idle_tag)
- {
- /* We just immediately re-enter in the case of idles (non-threads)
- * Anything else would just deadlock. If you can't handle this, enable threads.
- */
- func (user_data);
- if (notify)
- notify (user_data);
- return;
- }
-
proxy = g_new0 (MainLoopProxy, 1);
proxy->func = func;
proxy->data = user_data;
diff --git a/gio/gresolver.c b/gio/gresolver.c
index d08b3b5..433b23d 100644
--- a/gio/gresolver.c
+++ b/gio/gresolver.c
@@ -31,14 +31,11 @@
#include "ginetsocketaddress.h"
#include "gsimpleasyncresult.h"
#include "gsrvtarget.h"
+#include "gthreadedresolver.h"
#ifdef G_OS_UNIX
-#include "gunixresolver.h"
#include <sys/stat.h>
#endif
-#ifdef G_OS_WIN32
-#include "gwin32resolver.h"
-#endif
#include <stdlib.h>
@@ -153,18 +150,7 @@ GResolver *
g_resolver_get_default (void)
{
if (!default_resolver)
- {
- if (g_thread_supported ())
- default_resolver = g_object_new (G_TYPE_THREADED_RESOLVER, NULL);
- else
- {
-#if defined(G_OS_UNIX)
- default_resolver = g_object_new (G_TYPE_UNIX_RESOLVER, NULL);
-#elif defined(G_OS_WIN32)
- default_resolver = g_object_new (G_TYPE_WIN32_RESOLVER, NULL);
-#endif
- }
- }
+ default_resolver = g_object_new (G_TYPE_THREADED_RESOLVER, NULL);
return g_object_ref (default_resolver);
}
diff --git a/gio/gthreadedresolver.c b/gio/gthreadedresolver.c
index 4069048..7412bcd 100644
--- a/gio/gthreadedresolver.c
+++ b/gio/gthreadedresolver.c
@@ -42,9 +42,8 @@ static void threaded_resolver_thread (gpointer thread_data, gpointer pool_data);
static void
g_threaded_resolver_init (GThreadedResolver *gtr)
{
- if (g_thread_supported ())
- gtr->thread_pool = g_thread_pool_new (threaded_resolver_thread, gtr,
- -1, FALSE, NULL);
+ gtr->thread_pool = g_thread_pool_new (threaded_resolver_thread, gtr,
+ -1, FALSE, NULL);
}
static void
@@ -186,8 +185,7 @@ g_threaded_resolver_request_new (GThreadedResolverResolveFunc resolve_func,
/* Initial refcount is 2; one for the caller and one for resolve_func */
req->ref_count = 2;
- if (g_thread_supported ())
- req->mutex = g_mutex_new ();
+ req->mutex = g_mutex_new ();
/* Initially locked; caller must unlock */
g_mutex_lock (req->mutex);
diff --git a/gio/tests/resolver.c b/gio/tests/resolver.c
index 0b2a3fd..cec4e26 100644
--- a/gio/tests/resolver.c
+++ b/gio/tests/resolver.c
@@ -40,13 +40,11 @@ static int nlookups = 0;
static void G_GNUC_NORETURN
usage (void)
{
- fprintf (stderr, "Usage: resolver [-t] [-s] [hostname | IP | service/protocol/domain ] ...\n");
- fprintf (stderr, " resolver [-t] [-s] -c NUMBER [hostname | IP | service/protocol/domain ]\n");
- fprintf (stderr, " Use -t to enable threading.\n");
+ fprintf (stderr, "Usage: resolver [-s] [hostname | IP | service/protocol/domain ] ...\n");
+ fprintf (stderr, " resolver [-s] -c NUMBER [hostname | IP | service/protocol/domain ]\n");
fprintf (stderr, " Use -s to do synchronous lookups.\n");
- fprintf (stderr, " Both together will result in simultaneous lookups in multiple threads\n");
- fprintf (stderr, " Use -c NUMBER(and only a single resolvable argument) to test GSocketConnectable.\n");
- fprintf (stderr, " The given NUMBER determines how often the connectable will be enumerated.\n");
+ fprintf (stderr, " Use -c NUMBER (and only a single resolvable argument) to test GSocketConnectable.\n");
+ fprintf (stderr, " The given NUMBER determines how many times the connectable will be enumerated.\n");
exit (1);
}
@@ -198,21 +196,12 @@ lookup_thread (gpointer arg)
}
static void
-start_threaded_lookups (char **argv, int argc)
-{
- int i;
-
- for (i = 0; i < argc; i++)
- g_thread_create (lookup_thread, argv[i], FALSE, NULL);
-}
-
-static void
start_sync_lookups (char **argv, int argc)
{
int i;
for (i = 0; i < argc; i++)
- lookup_one_sync (argv[i]);
+ g_thread_create (lookup_thread, argv[i], FALSE, NULL);
}
static void
@@ -438,24 +427,19 @@ async_cancel (GIOChannel *source, GIOCondition cond, gpointer cancel)
int
main (int argc, char **argv)
{
- gboolean threaded = FALSE, synchronous = FALSE;
+ gboolean synchronous = FALSE;
guint connectable_count = 0;
#ifdef G_OS_UNIX
GIOChannel *chan;
guint watch;
#endif
- /* We can't use GOptionContext because we use the arguments to
- * decide whether or not to call g_thread_init().
- */
+ g_type_init ();
+
+ /* FIXME: use GOptionContext */
while (argc >= 2 && argv[1][0] == '-')
{
- if (!strcmp (argv[1], "-t"))
- {
- g_thread_init (NULL);
- threaded = TRUE;
- }
- else if (!strcmp (argv[1], "-s"))
+ if (!strcmp (argv[1], "-s"))
synchronous = TRUE;
else if (!strcmp (argv[1], "-c"))
{
@@ -469,7 +453,6 @@ main (int argc, char **argv)
argv++;
argc--;
}
- g_type_init ();
if (argc < 2 || (argc > 2 && connectable_count))
usage ();
@@ -504,9 +487,7 @@ main (int argc, char **argv)
}
else
{
- if (threaded && synchronous)
- start_threaded_lookups (argv + 1, argc - 1);
- else if (synchronous)
+ if (synchronous)
start_sync_lookups (argv + 1, argc - 1);
else
start_async_lookups (argv + 1, argc - 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]