data->context = g_main_context_new ();
data->loop = g_main_loop_new (data->context, FALSE);
- data->thread = g_thread_create (gdbus_shared_thread_func,
- data,
- TRUE,
- &error);
+ data->thread = g_thread_new ("gdbus",
+ gdbus_shared_thread_func,
+ data,
+ TRUE,
+ &error);
g_assert_no_error (error);
/* We can cast between gsize and gpointer safely */
g_once_init_leave (&shared_thread_data, (gsize) data);
SharedThreadData *shared_thread_data;
- gboolean stopped;
+ /* really a boolean, but GLib 2.28 lacks atomic boolean ops */
+ volatile gint stopped;
/* TODO: frozen (e.g. G_DBUS_CONNECTION_FLAGS_DELAY_MESSAGE_PROCESSING) currently
* only affects messages received from the other peer (since GDBusServer is the
gboolean remote_peer_vanished,
GError *error)
{
- if (!worker->stopped)
+ if (!g_atomic_int_get (&worker->stopped))
worker->disconnected_callback (worker, remote_peer_vanished, error, worker->user_data);
}
_g_dbus_worker_emit_message_received (GDBusWorker *worker,
GDBusMessage *message)
{
- if (!worker->stopped)
+ if (!g_atomic_int_get (&worker->stopped))
worker->message_received_callback (worker, message, worker->user_data);
}
GDBusMessage *message)
{
GDBusMessage *ret;
- if (!worker->stopped)
+ if (!g_atomic_int_get (&worker->stopped))
ret = worker->message_about_to_be_sent_callback (worker, message, worker->user_data);
else
ret = message;
g_mutex_lock (worker->read_lock);
/* If already stopped, don't even process the reply */
- if (worker->stopped)
+ if (g_atomic_int_get (&worker->stopped))
goto out;
error = NULL;
g_source_set_priority (idle_source, G_PRIORITY_DEFAULT);
g_source_set_callback (idle_source,
_g_dbus_worker_do_initial_read,
- worker,
- NULL);
+ _g_dbus_worker_ref (worker),
+ (GDestroyNotify) _g_dbus_worker_unref);
g_source_attach (idle_source, worker->shared_thread_data->context);
g_source_unref (idle_source);
void
_g_dbus_worker_stop (GDBusWorker *worker)
{
- worker->stopped = TRUE;
+ g_atomic_int_set (&worker->stopped, TRUE);
/* Cancel any pending operations and schedule a close of the underlying I/O
* stream in the worker thread