[gnome-keyring] Cleanup extra gkr_wakeup functionality
- From: Stefan Walter <stefw src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnome-keyring] Cleanup extra gkr_wakeup functionality
- Date: Mon, 11 May 2009 21:40:08 -0400 (EDT)
commit a85e0dd4b3bddb1be7e359d05bb4a6ee35ead3e8
Author: Stef Walter <stef memberwebs com>
Date: Sun May 10 14:34:54 2009 +0000
Cleanup extra gkr_wakeup functionality
Use g_main_context_wakeup where appropriate, and move some code
into the gkr_unix_signal stuff.
---
common/Makefile.am | 3 +-
common/gkr-async.c | 12 +----
common/gkr-unix-signal.c | 96 ++++++++++++++++++++++++++++++++++++++---
common/gkr-wakeup.c | 107 ----------------------------------------------
common/gkr-wakeup.h | 37 ----------------
5 files changed, 93 insertions(+), 162 deletions(-)
diff --git a/common/Makefile.am b/common/Makefile.am
index a000def..3c2ce4a 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -23,8 +23,7 @@ libgkr_common_la_SOURCES = \
gkr-cleanup.c gkr-cleanup.h \
gkr-location.c gkr-location.h \
gkr-location-watch.c gkr-location-watch.h \
- gkr-unix-signal.c gkr-unix-signal.h \
- gkr-wakeup.c gkr-wakeup.h
+ gkr-unix-signal.c gkr-unix-signal.h
libgkr_common_la_LIBADD = \
$(top_builddir)/egg/libegg.la \
diff --git a/common/gkr-async.c b/common/gkr-async.c
index a786e08..401bbe9 100644
--- a/common/gkr-async.c
+++ b/common/gkr-async.c
@@ -23,7 +23,6 @@
#include "gkr-async.h"
-#include "gkr-wakeup.h"
#include <glib.h>
@@ -42,7 +41,7 @@
#define DO_LOCK(mtx) G_STMT_START { \
g_printerr ("%s LOCK %s\n", __func__, G_STRINGIFY(mtx)); \
g_atomic_int_inc (&waiting_on_lock); \
- if (g_atomic_int_get (&waiting_on_poll)) gkr_wakeup_now (); \
+ if (g_atomic_int_get (&waiting_on_poll)) g_main_context_wakeup (main_ctx); \
g_mutex_lock (mtx); \
g_atomic_int_add (&waiting_on_lock, -1); \
} G_STMT_END
@@ -53,7 +52,7 @@
#else
#define DO_LOCK(mtx) G_STMT_START { \
g_atomic_int_inc (&waiting_on_lock); \
- if (g_atomic_int_get (&waiting_on_poll)) gkr_wakeup_now (); \
+ if (g_atomic_int_get (&waiting_on_poll)) g_main_context_wakeup (main_ctx); \
g_mutex_lock (mtx); \
g_atomic_int_add (&waiting_on_lock, -1); \
} G_STMT_END
@@ -135,7 +134,6 @@ static gboolean
async_source_dispatch(GSource* source, GSourceFunc callback, gpointer user_data)
{
/* Let a worker run */
- gkr_wakeup_drain ();
DO_UNLOCK (async_mutex);
g_thread_yield ();
DO_LOCK (async_mutex);
@@ -180,8 +178,6 @@ gkr_async_workers_init (GMainLoop *mainloop)
g_assert (orig_poll_func);
g_main_context_set_poll_func (main_ctx, async_poll_func);
- gkr_wakeup_register (main_ctx);
-
/*
* The mutex gets locked each time the main loop is waiting
* for input. See lock_step_poll_func()
@@ -198,8 +194,6 @@ gkr_async_workers_uninit (void)
DO_UNLOCK (async_mutex);
- gkr_wakeup_unregister ();
-
/* Take out the source */
g_assert (async_source_id);
src = g_main_context_find_source_by_id(main_ctx, async_source_id);
@@ -278,7 +272,7 @@ async_worker_thread (gpointer data)
g_static_private_set (&thread_private, NULL, NULL);
- gkr_wakeup_now ();
+ g_main_context_wakeup (main_ctx);
g_thread_exit (result);
return result;
diff --git a/common/gkr-unix-signal.c b/common/gkr-unix-signal.c
index f1eb239..9610f50 100644
--- a/common/gkr-unix-signal.c
+++ b/common/gkr-unix-signal.c
@@ -24,15 +24,97 @@
#include "config.h"
#include "gkr-unix-signal.h"
-#include "gkr-wakeup.h"
#include <glib.h>
#include <sys/types.h>
#include <errno.h>
+#include <fcntl.h>
#include <signal.h>
+#include <string.h>
#include <unistd.h>
+/* ------------------------------------------------------------------------
+ * MAIN LOOP WAKEUP
+ */
+
+static int wakeup_fds[2] = { -1, -1 };
+static guint wakeup_n = 0;
+static GPollFD poll_fd;
+static GMainContext *main_ctx;
+
+static void
+wakeup_register (GMainContext *ctx)
+{
+ if (wakeup_n++ == 0) {
+ if (pipe (wakeup_fds))
+ g_critical ("can't create wakeup pipe: %s", g_strerror (errno));
+
+ /* Non blocking to prevent deadlock */
+ fcntl (wakeup_fds[0], F_SETFL, fcntl (wakeup_fds[0], F_GETFL) | O_NONBLOCK);
+ fcntl (wakeup_fds[1], F_SETFL, fcntl (wakeup_fds[1], F_GETFL) | O_NONBLOCK);
+
+ /* Register poll fd with main context */
+ poll_fd.fd = wakeup_fds[0];
+ poll_fd.events = G_IO_IN;
+ poll_fd.revents = 0;
+
+ g_main_context_add_poll (ctx, &poll_fd, G_PRIORITY_HIGH_IDLE);
+ main_ctx = ctx;
+ }
+
+ g_assert (wakeup_fds[0] >= 0);
+}
+static void
+
+wakeup_unregister (void)
+{
+ if (--wakeup_n > 0)
+ return;
+
+ g_assert (wakeup_fds[0] >= 0);
+ close (wakeup_fds[0]);
+ wakeup_fds[0] = -1;
+
+ g_assert (wakeup_fds[1] >= 0);
+ close (wakeup_fds[1]);
+ wakeup_fds[1] = -1;
+
+ g_assert (main_ctx);
+ g_main_context_remove_poll (main_ctx, &poll_fd);
+ main_ctx = NULL;
+}
+
+static void
+wakeup_now (void)
+{
+ #define SIG_MSG "couldn't write signal byte to pipe\n"
+ guchar x = 0xAA;
+ int res;
+
+ if (wakeup_fds[1] < 0)
+ return;
+
+ /* Could be called from a signal handler, so try to not use library functions */
+ if (write (wakeup_fds[1], &x, 1) != 1)
+ res = write (2, SIG_MSG, strlen (SIG_MSG) - 1);
+}
+
+static void
+wakeup_drain (void)
+{
+ guchar x;
+
+ if (wakeup_fds[0] < 0)
+ return;
+
+ while (read (wakeup_fds[0], &x, 1) > 0);
+}
+
+/* ------------------------------------------------------------------------
+ * SIGNAL STUFF
+ */
+
#define MAX_SIGNAL 64
static gboolean handled_signals[MAX_SIGNAL] = { FALSE, };
static gboolean received_signals[MAX_SIGNAL] = { FALSE, };
@@ -42,7 +124,7 @@ signal_handler (int sig)
{
if (sig >= 0 && sig < MAX_SIGNAL) {
received_signals[sig] = TRUE;
- gkr_wakeup_now ();
+ wakeup_now ();
}
}
@@ -56,7 +138,7 @@ signal_events_prepare (GSource *source, gint *timeout)
{
SignalWatch *sw = (SignalWatch*)source;
*timeout = -1;
- gkr_wakeup_drain ();
+ wakeup_drain ();
g_assert (sw->signal < MAX_SIGNAL);
return received_signals[sw->signal];
}
@@ -65,7 +147,7 @@ static gboolean
signal_events_check (GSource *source)
{
SignalWatch *sw = (SignalWatch*)source;
- gkr_wakeup_drain ();
+ wakeup_drain ();
g_assert (sw->signal < MAX_SIGNAL);
return received_signals[sw->signal];
}
@@ -76,7 +158,7 @@ signal_events_dispatch (GSource *source, GSourceFunc callback, gpointer user_dat
SignalWatch *sw = (SignalWatch*)source;
GkrUnixSignalHandler func = (GkrUnixSignalHandler)callback;
- gkr_wakeup_drain ();
+ wakeup_drain ();
g_assert (sw->signal < MAX_SIGNAL);
g_assert (received_signals[sw->signal]);
@@ -92,7 +174,7 @@ signal_events_finalize (GSource *source)
{
SignalWatch *sw = (SignalWatch*)source;
- gkr_wakeup_unregister ();
+ wakeup_unregister ();
g_assert (sw->signal < MAX_SIGNAL);
if (sw->signal > 0)
@@ -128,7 +210,7 @@ gkr_unix_signal_connect (GMainContext *ctx, guint sig,
sw = (SignalWatch*)src;
sw->signal = sig;
- gkr_wakeup_register (ctx);
+ wakeup_register (ctx);
g_source_set_callback (src, (GSourceFunc)func, user_data, NULL);
id = g_source_attach (src, ctx);
diff --git a/common/gkr-wakeup.c b/common/gkr-wakeup.c
deleted file mode 100644
index a1ab88e..0000000
--- a/common/gkr-wakeup.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gkr-wakeup.c - wakeup GSource for arbitrary events
-
- Copyright (C) 2007 Stefan Walter
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Stef Walter <stef memberwebs com>
-*/
-
-#include "config.h"
-
-#include "gkr-wakeup.h"
-
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <glib.h>
-
-static int wakeup_fds[2] = { -1, -1 };
-static guint wakeup_n = 0;
-static GPollFD poll_fd;
-static GMainContext *main_ctx;
-
-void
-gkr_wakeup_register (GMainContext *ctx)
-{
- if (wakeup_n++ == 0) {
- if (pipe (wakeup_fds))
- g_critical ("can't create wakeup pipe: %s", g_strerror (errno));
-
- /* Non blocking to prevent deadlock */
- fcntl (wakeup_fds[0], F_SETFL, fcntl (wakeup_fds[0], F_GETFL) | O_NONBLOCK);
- fcntl (wakeup_fds[1], F_SETFL, fcntl (wakeup_fds[1], F_GETFL) | O_NONBLOCK);
-
- /* Register poll fd with main context */
- poll_fd.fd = wakeup_fds[0];
- poll_fd.events = G_IO_IN;
- poll_fd.revents = 0;
-
- g_main_context_add_poll (ctx, &poll_fd, G_PRIORITY_HIGH_IDLE);
- main_ctx = ctx;
- }
-
- g_assert (wakeup_fds[0] >= 0);
-}
-
-void
-gkr_wakeup_unregister (void)
-{
- if (--wakeup_n > 0)
- return;
-
- g_assert (wakeup_fds[0] >= 0);
- close (wakeup_fds[0]);
- wakeup_fds[0] = -1;
-
- g_assert (wakeup_fds[1] >= 0);
- close (wakeup_fds[1]);
- wakeup_fds[1] = -1;
-
- g_assert (main_ctx);
- g_main_context_remove_poll (main_ctx, &poll_fd);
- main_ctx = NULL;
-}
-
-void
-gkr_wakeup_now (void)
-{
- #define SIG_MSG "couldn't write signal byte to pipe\n"
- guchar x = 0xAA;
- int res;
-
- if (wakeup_fds[1] < 0)
- return;
-
- /* Could be called from a signal handler, so try to not use library functions */
- if (write (wakeup_fds[1], &x, 1) != 1)
- res = write (2, SIG_MSG, strlen (SIG_MSG) - 1);
-
-}
-
-void
-gkr_wakeup_drain (void)
-{
- guchar x;
-
- if (wakeup_fds[0] < 0)
- return;
-
- while (read (wakeup_fds[0], &x, 1) > 0);
-}
diff --git a/common/gkr-wakeup.h b/common/gkr-wakeup.h
deleted file mode 100644
index 2281297..0000000
--- a/common/gkr-wakeup.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
-/* gkr-wakeup.h - wakeup GSource for arbitrary events
-
- Copyright (C) 2007 Stefan Walter
-
- The Gnome Keyring Library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Library General Public License as
- published by the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
-
- The Gnome Keyring Library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Library General Public License for more details.
-
- You should have received a copy of the GNU Library General Public
- License along with the Gnome Library; see the file COPYING.LIB. If not,
- write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
-
- Author: Stef Walter <stef memberwebs com>
-*/
-
-#ifndef GKRWAKEUP_H_
-#define GKRWAKEUP_H_
-
-#include <glib.h>
-
-void gkr_wakeup_register (GMainContext *ctx);
-
-void gkr_wakeup_unregister (void);
-
-void gkr_wakeup_now (void);
-
-void gkr_wakeup_drain (void);
-
-#endif /*GKRWAKEUP_H_*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]