[telepathy-mission-control/master] McdDispatchOperation: track approvers that haven't replied to AddDispatchOperation
Simon McVittie
simon.mcvittie at collabora.co.uk
Tue Oct 20 08:47:21 PDT 2009
No "much ADO() about nothing" pun intended.
---
src/mcd-dispatch-operation-priv.h | 8 +++++++
src/mcd-dispatch-operation.c | 41 +++++++++++++++++++++++++++++++++++++
src/mcd-dispatcher.c | 21 ++++++------------
3 files changed, 56 insertions(+), 14 deletions(-)
diff --git a/src/mcd-dispatch-operation-priv.h b/src/mcd-dispatch-operation-priv.h
index aed2d34..f0d548c 100644
--- a/src/mcd-dispatch-operation-priv.h
+++ b/src/mcd-dispatch-operation-priv.h
@@ -116,6 +116,14 @@ G_GNUC_INTERNAL void _mcd_dispatch_operation_inc_observers_pending (
G_GNUC_INTERNAL void _mcd_dispatch_operation_dec_observers_pending (
McdDispatchOperation *self);
+/* AddDispatchOperation calls */
+G_GNUC_INTERNAL gboolean _mcd_dispatch_operation_has_ado_pending (
+ McdDispatchOperation *self);
+G_GNUC_INTERNAL void _mcd_dispatch_operation_inc_ado_pending (
+ McdDispatchOperation *self);
+G_GNUC_INTERNAL void _mcd_dispatch_operation_dec_ado_pending (
+ McdDispatchOperation *self);
+
G_END_DECLS
#endif
diff --git a/src/mcd-dispatch-operation.c b/src/mcd-dispatch-operation.c
index 1d316de..8939697 100644
--- a/src/mcd-dispatch-operation.c
+++ b/src/mcd-dispatch-operation.c
@@ -118,6 +118,14 @@ struct _McdDispatchOperationPrivate
* A reference is held for each pending observer (and in the
* McdDispatcherContext, one instance of CTXREF05 is held for each). */
gsize observers_pending;
+
+ /* The number of approvers that have not yet returned from
+ * AddDispatchOperation. Until they have done so, we can't allow the
+ * dispatch operation to finish. This is a client lock.
+ *
+ * A reference is held for each pending approver (and in the
+ * McdDispatcherContext, one instance of CTXREF06 is held for each). */
+ gsize ado_pending;
};
gboolean
@@ -155,6 +163,39 @@ _mcd_dispatch_operation_dec_observers_pending (McdDispatchOperation *self)
g_object_unref (self);
}
+gboolean
+_mcd_dispatch_operation_has_ado_pending (McdDispatchOperation *self)
+{
+ g_return_val_if_fail (MCD_IS_DISPATCH_OPERATION (self), FALSE);
+ return (self->priv->ado_pending > 0);
+}
+
+void
+_mcd_dispatch_operation_inc_ado_pending (McdDispatchOperation *self)
+{
+ g_return_if_fail (MCD_IS_DISPATCH_OPERATION (self));
+
+ g_object_ref (self);
+
+ DEBUG ("%" G_GSIZE_FORMAT " -> %" G_GSIZE_FORMAT,
+ self->priv->ado_pending,
+ self->priv->ado_pending + 1);
+ self->priv->ado_pending++;
+}
+
+void
+_mcd_dispatch_operation_dec_ado_pending (McdDispatchOperation *self)
+{
+ g_return_if_fail (MCD_IS_DISPATCH_OPERATION (self));
+ DEBUG ("%" G_GSIZE_FORMAT " -> %" G_GSIZE_FORMAT,
+ self->priv->ado_pending,
+ self->priv->ado_pending - 1);
+ g_return_if_fail (self->priv->ado_pending > 0);
+ self->priv->ado_pending--;
+
+ g_object_unref (self);
+}
+
enum
{
PROP_0,
diff --git a/src/mcd-dispatcher.c b/src/mcd-dispatcher.c
index cd863e7..867e0a9 100644
--- a/src/mcd-dispatcher.c
+++ b/src/mcd-dispatcher.c
@@ -113,13 +113,6 @@ struct _McdDispatcherContext
GList *channels;
McdDispatchOperation *operation;
- /* The number of approvers that have not yet returned from
- * AddDispatchOperation. Until they have done so, we can't allow the
- * dispatch operation to finish. This is a client lock.
- *
- * One instance of CTXREF06 is held for each pending approver. */
- gsize approvers_pending;
-
/* State-machine internal data fields: */
GList *chain;
@@ -1067,10 +1060,9 @@ mcd_dispatcher_run_observers (McdDispatcherContext *context)
static void
mcd_dispatcher_context_release_pending_approver (McdDispatcherContext *context)
{
- g_return_if_fail (context->approvers_pending > 0);
- context->approvers_pending--;
+ _mcd_dispatch_operation_dec_ado_pending (context->operation);
- if (context->approvers_pending == 0 &&
+ if (!_mcd_dispatch_operation_has_ado_pending (context->operation) &&
!context->awaiting_approval)
{
DEBUG ("No approver accepted the channels; considering them to be "
@@ -1138,7 +1130,7 @@ mcd_dispatcher_run_approvers (McdDispatcherContext *context)
/* we temporarily increment this count and decrement it at the end of the
* function, to make sure it won't become 0 while we are still invoking
* approvers */
- context->approvers_pending = 1;
+ _mcd_dispatch_operation_inc_ado_pending (context->operation);
channels = context->channels;
_mcd_client_registry_init_hash_iter (priv->clients, &iter);
@@ -1179,7 +1171,7 @@ mcd_dispatcher_run_approvers (McdDispatcherContext *context)
"of context %p", tp_proxy_get_bus_name (client),
dispatch_operation, context->operation, context);
- context->approvers_pending++;
+ _mcd_dispatch_operation_inc_ado_pending (context->operation);
_mcd_dispatch_operation_block_finished (context->operation);
mcd_dispatcher_context_ref (context, "CTXREF06");
@@ -1332,7 +1324,7 @@ on_operation_finished (McdDispatchOperation *operation,
/* Because of our calls to _mcd_dispatch_operation_block_finished,
* this cannot happen until all observers and all approvers have
* returned from ObserveChannels or AddDispatchOperation, respectively. */
- g_assert (context->approvers_pending == 0);
+ g_assert (!_mcd_dispatch_operation_has_ado_pending (context->operation));
g_assert (!_mcd_dispatch_operation_has_observers_pending
(context->operation));
@@ -2671,7 +2663,8 @@ _mcd_dispatcher_add_channel_request (McdDispatcher *dispatcher,
context = find_context_from_channel (dispatcher, channel);
DEBUG ("channel %p is in context %p", channel, context);
- if (context->approvers_pending > 0 || context->awaiting_approval)
+ if (_mcd_dispatch_operation_has_ado_pending (context->operation)
+ || context->awaiting_approval)
{
/* the existing channel is waiting for approval; but since the
* same channel has been requested, the approval operation must
--
1.5.6.5
More information about the telepathy-commits
mailing list