diff --git a/src/core/stack-tracker.c b/src/core/stack-tracker.c index c830fbbb9..94158079b 100644 --- a/src/core/stack-tracker.c +++ b/src/core/stack-tracker.c @@ -54,8 +54,8 @@ * * When we receive a new event: a) we compare the serial in the event to * the serial of the queued requests and remove any that are now - * no longer pending b) drop the predicted stacking order to recompute - * it at the next opportunity. + * no longer pending b) if necessary, drop the predicted stacking + * order to recompute it at the next opportunity. * * Possible optimizations: * Keep the stacks as an array + reverse-mapping hash table to avoid @@ -505,6 +505,8 @@ static void stack_tracker_event_received (MetaStackTracker *tracker, MetaStackOp *op) { + gboolean need_sync = FALSE; + meta_stack_op_dump (op, "Stack op event received: ", "\n"); if (op->any.serial < tracker->server_serial) @@ -512,7 +514,8 @@ stack_tracker_event_received (MetaStackTracker *tracker, tracker->server_serial = op->any.serial; - meta_stack_op_apply (op, tracker->server_stack); + if (meta_stack_op_apply (op, tracker->server_stack)) + need_sync = TRUE; while (tracker->queued_requests->head) { @@ -522,17 +525,21 @@ stack_tracker_event_received (MetaStackTracker *tracker, g_queue_pop_head (tracker->queued_requests); meta_stack_op_free (queued_op); + need_sync = TRUE; } - if (tracker->predicted_stack) + if (need_sync) { - g_array_free (tracker->predicted_stack, TRUE); - tracker->predicted_stack = NULL; + if (tracker->predicted_stack) + { + g_array_free (tracker->predicted_stack, TRUE); + tracker->predicted_stack = NULL; + } + + meta_stack_tracker_queue_sync_stack (tracker); } meta_stack_tracker_dump (tracker); - - meta_stack_tracker_queue_sync_stack (tracker); } void