[libgda] GdaThreadWrapper: modified gda_thread_wrapper_connect_raw()
- From: Vivien Malerba <vivien src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [libgda] GdaThreadWrapper: modified gda_thread_wrapper_connect_raw()
- Date: Sun, 13 Sep 2009 18:45:00 +0000 (UTC)
commit 129b03a644801553246bdcb9b7e5cde1ddb8c4ec
Author: Vivien Malerba <malerba gnome-db org>
Date: Sun Sep 13 20:44:21 2009 +0200
GdaThreadWrapper: modified gda_thread_wrapper_connect_raw()
* add a new @private argument
* also correct some bugs with the GdaBrowser when multiple
windows were being used for the same connection
doc/C/tmpl/gda-thread-wrapper.sgml | 1 +
libgda/gda-connection.c | 7 +++++++
libgda/thread-wrapper/gda-thread-provider.c | 17 ++++++-----------
libgda/thread-wrapper/gda-thread-wrapper.c | 14 ++++++++++++--
libgda/thread-wrapper/gda-thread-wrapper.h | 2 +-
tests/multi-threading/check_wrapper.c | 6 +++---
tools/browser/query-exec/query-exec-perspective.c | 19 +++++++++++++------
7 files changed, 43 insertions(+), 23 deletions(-)
---
diff --git a/doc/C/tmpl/gda-thread-wrapper.sgml b/doc/C/tmpl/gda-thread-wrapper.sgml
index 63eb1e4..090dfdc 100644
--- a/doc/C/tmpl/gda-thread-wrapper.sgml
+++ b/doc/C/tmpl/gda-thread-wrapper.sgml
@@ -181,6 +181,7 @@ Execute functions in a sub thread
@wrapper:
@instance:
@sig_name:
+ private:
@callback:
@data:
@Returns:
diff --git a/libgda/gda-connection.c b/libgda/gda-connection.c
index 59592db..b73909c 100644
--- a/libgda/gda-connection.c
+++ b/libgda/gda-connection.c
@@ -694,6 +694,13 @@ gda_connection_set_property (GObject *object,
cnc->priv->monitor_id = g_timeout_add_seconds (1,
(GSourceFunc) monitor_wrapped_cnc,
cdata->wrapper);
+ /* steal signals for current thread */
+ gint i;
+ for (i = 0; i < cdata->handlers_ids->len; i++) {
+ gulong id;
+ id = g_array_index (cdata->handlers_ids, gulong, i);
+ gda_thread_wrapper_steal_signal (cdata->wrapper, id);
+ }
}
}
}
diff --git a/libgda/thread-wrapper/gda-thread-provider.c b/libgda/thread-wrapper/gda-thread-provider.c
index b547263..ff3030a 100644
--- a/libgda/thread-wrapper/gda-thread-provider.c
+++ b/libgda/thread-wrapper/gda-thread-provider.c
@@ -475,11 +475,14 @@ static void
setup_signals (GdaConnection *cnc, ThreadConnectionData *cdata)
{
gulong hid;
- hid = gda_thread_wrapper_connect_raw (cdata->wrapper, cdata->sub_connection, "error",
+ hid = gda_thread_wrapper_connect_raw (cdata->wrapper, cdata->sub_connection,
+ "error", FALSE,
(GdaThreadWrapperCallback) sub_cnc_error_cb, cnc);
g_array_prepend_val (cdata->handlers_ids, hid);
- hid = gda_thread_wrapper_connect_raw (cdata->wrapper, cdata->sub_connection, "transaction-status-changed",
- (GdaThreadWrapperCallback) sub_cnc_transaction_status_changed_cb, cnc);
+ hid = gda_thread_wrapper_connect_raw (cdata->wrapper, cdata->sub_connection,
+ "transaction-status-changed", FALSE,
+ (GdaThreadWrapperCallback) sub_cnc_transaction_status_changed_cb,
+ cnc);
g_array_prepend_val (cdata->handlers_ids, hid);
}
@@ -1503,14 +1506,6 @@ gda_thread_provider_statement_execute (GdaServerProvider *provider, GdaConnectio
cdata = (ThreadConnectionData*) gda_connection_internal_get_provider_data (cnc);
if (!cdata)
return FALSE;
-
- /* steal signals for current thread */
- gint i;
- for (i = 0; i < cdata->handlers_ids->len; i++) {
- gulong id;
- id = g_array_index (cdata->handlers_ids, gulong, i);
- gda_thread_wrapper_steal_signal (cdata->wrapper, id);
- }
if (async_cb) {
ExecuteStatementData *wdata;
diff --git a/libgda/thread-wrapper/gda-thread-wrapper.c b/libgda/thread-wrapper/gda-thread-wrapper.c
index bd88d5a..3c84034 100644
--- a/libgda/thread-wrapper/gda-thread-wrapper.c
+++ b/libgda/thread-wrapper/gda-thread-wrapper.c
@@ -123,6 +123,7 @@ job_free (Job *job)
struct _SignalSpec {
GSignalQuery sigprop; /* must be first */
+ gboolean private;
GThread *worker_thread;
GAsyncQueue *reply_queue; /* a ref is held here */
@@ -921,7 +922,8 @@ worker_thread_closure_marshal (GClosure *closure,
return;
/* check that the worker thread is working on a job for which job->reply_queue == sigspec->reply_queue */
- if (g_static_private_get (&worker_thread_current_queue) != sigspec->reply_queue)
+ if (sigspec->private &&
+ g_static_private_get (&worker_thread_current_queue) != sigspec->reply_queue)
return;
gint i;
@@ -957,6 +959,9 @@ worker_thread_closure_marshal (GClosure *closure,
* @wrapper: a #GdaThreadWrapper object
* @instance: the instance to connect to
* @sig_name: a string of the form "signal-name::detail"
+ * @private: set to %TRUE if @callback is to be invoked only if the signal has
+ * been emitted when a job created for the calling thread is being executed, and to %FALSE
+ * if @callback has to be called whenever the @sig_name signa is emitted by @instance.
* @callback: a #GdaThreadWrapperCallback function
* @data: data to pass to @callback's calls
*
@@ -972,6 +977,10 @@ worker_thread_closure_marshal (GClosure *closure,
* while being used in @wrapper's private sub thread (ie. used when @wrapper is executing some functions
* specified by
* gda_thread_wrapper_execute() or gda_thread_wrapper_execute_void())</para></listitem>
+ * <listitem><para>if @private is set to %TRUE, then the @callback function will be called only
+ * if the signal has been emitted by @instance while doing a job on behalf of the current
+ * calling thread. If @private is set to %FALSE, then @callback will be called whenever @instance
+ * emits the @sig_name signal.</para></listitem>
* </itemizedlist>
*
* Also note that signal handling is done asynchronously: when emitted in the worker thread, it
@@ -989,7 +998,7 @@ worker_thread_closure_marshal (GClosure *closure,
gulong
gda_thread_wrapper_connect_raw (GdaThreadWrapper *wrapper,
gpointer instance,
- const gchar *sig_name,
+ const gchar *sig_name, gboolean private,
GdaThreadWrapperCallback callback,
gpointer data)
{
@@ -1012,6 +1021,7 @@ gda_thread_wrapper_connect_raw (GdaThreadWrapper *wrapper,
}
sigspec = g_new0 (SignalSpec, 1);
+ sigspec->private = private;
g_signal_query (sigid, (GSignalQuery*) sigspec);
if (((GSignalQuery*) sigspec)->return_type != G_TYPE_NONE) {
diff --git a/libgda/thread-wrapper/gda-thread-wrapper.h b/libgda/thread-wrapper/gda-thread-wrapper.h
index 7256a2b..564c40a 100644
--- a/libgda/thread-wrapper/gda-thread-wrapper.h
+++ b/libgda/thread-wrapper/gda-thread-wrapper.h
@@ -82,7 +82,7 @@ gint gda_thread_wrapper_get_waiting_size (GdaThreadWrapper *wr
gulong gda_thread_wrapper_connect_raw (GdaThreadWrapper *wrapper,
gpointer instance,
- const gchar *sig_name,
+ const gchar *sig_name, gboolean private,
GdaThreadWrapperCallback callback,
gpointer data);
void gda_thread_wrapper_disconnect (GdaThreadWrapper *wrapper, gulong id);
diff --git a/tests/multi-threading/check_wrapper.c b/tests/multi-threading/check_wrapper.c
index 0056e03..d638289 100644
--- a/tests/multi-threading/check_wrapper.c
+++ b/tests/multi-threading/check_wrapper.c
@@ -526,13 +526,13 @@ t2_main_thread_func (DummyObject *dummy)
GSList *received_list = NULL;
/*g_print ("NEW test thread: %p\n", g_thread_self());*/
- sigid[0] = gda_thread_wrapper_connect_raw (wrapper, dummy, "sig0",
+ sigid[0] = gda_thread_wrapper_connect_raw (wrapper, dummy, "sig0", TRUE,
(GdaThreadWrapperCallback) wrapper_callback,
&received_list);
- sigid[1] = gda_thread_wrapper_connect_raw (wrapper, dummy, "sig1",
+ sigid[1] = gda_thread_wrapper_connect_raw (wrapper, dummy, "sig1", TRUE,
(GdaThreadWrapperCallback) wrapper_callback,
&received_list);
- sigid[2] = gda_thread_wrapper_connect_raw (wrapper, dummy, "sig2",
+ sigid[2] = gda_thread_wrapper_connect_raw (wrapper, dummy, "sig2", TRUE,
(GdaThreadWrapperCallback) wrapper_callback,
&received_list);
diff --git a/tools/browser/query-exec/query-exec-perspective.c b/tools/browser/query-exec/query-exec-perspective.c
index 76649e0..89633e4 100644
--- a/tools/browser/query-exec/query-exec-perspective.c
+++ b/tools/browser/query-exec/query-exec-perspective.c
@@ -45,6 +45,7 @@ static GObjectClass *parent_class = NULL;
struct _QueryExecPerspectivePrivate {
GtkWidget *notebook;
BrowserWindow *bwin;
+ BrowserConnection *bcnc;
GtkActionGroup *action_group;
gboolean updating_transaction_status;
@@ -134,10 +135,11 @@ query_exec_perspective_new (BrowserWindow *bwin)
perspective = (QueryExecPerspective*) bpers;
perspective->priv->bwin = bwin;
+ bcnc = browser_window_get_connection (bwin);
+ perspective->priv->bcnc = g_object_ref (bcnc);
/* contents */
GtkWidget *paned, *nb;
- bcnc = browser_window_get_connection (bwin);
paned = gtk_hpaned_new ();
/*
wid = favorite_selector_new (bcnc);
@@ -230,6 +232,11 @@ query_exec_perspective_dispose (GObject *object)
perspective = QUERY_EXEC_PERSPECTIVE (object);
if (perspective->priv) {
+ g_signal_handlers_disconnect_by_func (perspective->priv->bcnc,
+ G_CALLBACK (transaction_status_changed_cb), perspective);
+ if (perspective->priv->bcnc)
+ g_object_unref (perspective->priv->bcnc);
+
if (perspective->priv->action_group)
g_object_unref (perspective->priv->action_group);
@@ -252,7 +259,7 @@ query_exec_add_cb (GtkAction *action, BrowserPerspective *bpers)
gint i;
perspective = QUERY_EXEC_PERSPECTIVE (bpers);
- bcnc = browser_window_get_connection (perspective->priv->bwin);
+ bcnc = perspective->priv->bcnc;
page = query_console_new (bcnc);
gtk_widget_show (page);
@@ -303,7 +310,7 @@ transaction_begin_cb (GtkAction *action, BrowserPerspective *bpers)
BrowserConnection *bcnc;
perspective = QUERY_EXEC_PERSPECTIVE (bpers);
- bcnc = browser_window_get_connection (perspective->priv->bwin);
+ bcnc = perspective->priv->bcnc;
if (!perspective->priv->updating_transaction_status) {
GError *error = NULL;
if (! browser_connection_begin (bcnc, &error)) {
@@ -322,7 +329,7 @@ transaction_commit_cb (GtkAction *action, BrowserPerspective *bpers)
BrowserConnection *bcnc;
perspective = QUERY_EXEC_PERSPECTIVE (bpers);
- bcnc = browser_window_get_connection (perspective->priv->bwin);
+ bcnc = perspective->priv->bcnc;
if (!perspective->priv->updating_transaction_status) {
GError *error = NULL;
if (! browser_connection_commit (bcnc, &error)) {
@@ -341,7 +348,7 @@ transaction_rollback_cb (GtkAction *action, BrowserPerspective *bpers)
BrowserConnection *bcnc;
perspective = QUERY_EXEC_PERSPECTIVE (bpers);
- bcnc = browser_window_get_connection (perspective->priv->bwin);
+ bcnc = perspective->priv->bcnc;
if (!perspective->priv->updating_transaction_status) {
GError *error = NULL;
if (! browser_connection_rollback (bcnc, &error)) {
@@ -400,7 +407,7 @@ query_exec_perspective_get_actions_group (BrowserPerspective *perspective)
bpers->priv->action_group = g_object_ref (agroup);
}
- transaction_status_changed_cb (browser_window_get_connection (bpers->priv->bwin), bpers);
+ transaction_status_changed_cb (bpers->priv->bcnc, bpers);
return bpers->priv->action_group;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]