GFileMonitor: thread-safety fix for non-default-main-context monitors
[platform/upstream/glib.git] / gio / gfilemonitor.c
1 /* GIO - GLib Input, Output and Streaming Library
2  * 
3  * Copyright (C) 2006-2007 Red Hat, Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General
16  * Public License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  * Boston, MA 02111-1307, USA.
19  *
20  * Author: Alexander Larsson <alexl@redhat.com>
21  */
22
23 #include "config.h"
24 #include <string.h>
25
26 #include "gfilemonitor.h"
27 #include "gioenumtypes.h"
28 #include "gfile.h"
29 #include "gvfs.h"
30 #include "glibintl.h"
31
32
33 struct _FileChange;
34 typedef struct _FileChange FileChange;
35 static void file_change_free (FileChange *change);
36
37 /**
38  * SECTION:gfilemonitor
39  * @short_description: File Monitor
40  * @include: gio/gio.h
41  *
42  * Monitors a file or directory for changes.
43  *
44  * To obtain a #GFileMonitor for a file or directory, use
45  * g_file_monitor(), g_file_monitor_file(), or
46  * g_file_monitor_directory().
47  *
48  * To get informed about changes to the file or directory you are
49  * monitoring, connect to the #GFileMonitor::changed signal. The
50  * signal will be emitted in the <link
51  * linkend="g-main-context-push-thread-default">thread-default main
52  * context</link> of the thread that the monitor was created in
53  * (though if the global default main context is blocked, this may
54  * cause notifications to be blocked even if the thread-default
55  * context is still running).
56  **/
57
58 G_LOCK_DEFINE_STATIC(cancelled);
59
60 enum {
61   CHANGED,
62   LAST_SIGNAL
63 };
64
65 /* work around a limitation of the aliasing foo */
66 #undef g_file_monitor
67
68 G_DEFINE_ABSTRACT_TYPE (GFileMonitor, g_file_monitor, G_TYPE_OBJECT);
69
70 typedef struct {
71   GFile *file;
72   guint32 last_sent_change_time; /* 0 == not sent */
73   guint32 send_delayed_change_at; /* 0 == never */
74   guint32 send_virtual_changes_done_at; /* 0 == never */
75 } RateLimiter;
76
77 struct _GFileMonitorPrivate {
78   gboolean cancelled;
79   int rate_limit_msec;
80
81   /* Rate limiting change events */
82   GHashTable *rate_limiter;
83
84   GMutex mutex;
85   GSource *pending_file_change_source;
86   GSList *pending_file_changes; /* FileChange */
87
88   GSource *timeout;
89   guint32 timeout_fires_at;
90
91   GMainContext *context;
92 };
93
94 enum {
95   PROP_0,
96   PROP_RATE_LIMIT,
97   PROP_CANCELLED
98 };
99
100 static void
101 g_file_monitor_set_property (GObject      *object,
102                              guint         prop_id,
103                              const GValue *value,
104                              GParamSpec   *pspec)
105 {
106   GFileMonitor *monitor;
107
108   monitor = G_FILE_MONITOR (object);
109
110   switch (prop_id)
111     {
112     case PROP_RATE_LIMIT:
113       g_file_monitor_set_rate_limit (monitor, g_value_get_int (value));
114       break;
115
116     default:
117       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
118       break;
119     }
120 }
121
122 static void
123 g_file_monitor_get_property (GObject    *object,
124                              guint       prop_id,
125                              GValue     *value,
126                              GParamSpec *pspec)
127 {
128   GFileMonitor *monitor;
129   GFileMonitorPrivate *priv;
130
131   monitor = G_FILE_MONITOR (object);
132   priv = monitor->priv;
133
134   switch (prop_id)
135     {
136     case PROP_RATE_LIMIT:
137       g_value_set_int (value, priv->rate_limit_msec);
138       break;
139
140     case PROP_CANCELLED:
141       G_LOCK (cancelled);
142       g_value_set_boolean (value, priv->cancelled);
143       G_UNLOCK (cancelled);
144       break;
145
146     default:
147       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
148       break;
149     }
150 }
151
152 #define DEFAULT_RATE_LIMIT_MSECS 800
153 #define DEFAULT_VIRTUAL_CHANGES_DONE_DELAY_SECS 2
154
155 static guint signals[LAST_SIGNAL] = { 0 };
156
157 static void
158 rate_limiter_free (RateLimiter *limiter)
159 {
160   g_object_unref (limiter->file);
161   g_slice_free (RateLimiter, limiter);
162 }
163
164 static void
165 g_file_monitor_finalize (GObject *object)
166 {
167   GFileMonitor *monitor;
168
169   monitor = G_FILE_MONITOR (object);
170
171   if (monitor->priv->timeout)
172     {
173       g_source_destroy (monitor->priv->timeout);
174       g_source_unref (monitor->priv->timeout);
175     }
176
177   g_hash_table_destroy (monitor->priv->rate_limiter);
178
179   g_main_context_unref (monitor->priv->context);
180   g_mutex_clear (&monitor->priv->mutex);
181
182   G_OBJECT_CLASS (g_file_monitor_parent_class)->finalize (object);
183 }
184
185 static void
186 g_file_monitor_dispose (GObject *object)
187 {
188   GFileMonitor *monitor;
189   GFileMonitorPrivate *priv;
190   
191   monitor = G_FILE_MONITOR (object);
192   priv = monitor->priv;
193
194   if (priv->pending_file_change_source)
195     {
196       g_source_destroy (priv->pending_file_change_source);
197       g_source_unref (priv->pending_file_change_source);
198       priv->pending_file_change_source = NULL;
199     }
200   g_slist_free_full (priv->pending_file_changes, (GDestroyNotify) file_change_free);
201   priv->pending_file_changes = NULL;
202
203   /* Make sure we cancel on last unref */
204   g_file_monitor_cancel (monitor);
205
206   G_OBJECT_CLASS (g_file_monitor_parent_class)->dispose (object);
207 }
208
209 static void
210 g_file_monitor_class_init (GFileMonitorClass *klass)
211 {
212   GObjectClass *object_class;
213   
214   g_type_class_add_private (klass, sizeof (GFileMonitorPrivate));
215   
216   object_class = G_OBJECT_CLASS (klass);
217   object_class->finalize = g_file_monitor_finalize;
218   object_class->dispose = g_file_monitor_dispose;
219   object_class->get_property = g_file_monitor_get_property;
220   object_class->set_property = g_file_monitor_set_property;
221
222   /**
223    * GFileMonitor::changed:
224    * @monitor: a #GFileMonitor.
225    * @file: a #GFile.
226    * @other_file: (allow-none): a #GFile or #NULL.
227    * @event_type: a #GFileMonitorEvent.
228    *
229    * Emitted when @file has been changed.
230    *
231    * If using #G_FILE_MONITOR_SEND_MOVED flag and @event_type is
232    * #G_FILE_MONITOR_EVENT_MOVED, @file will be set to a #GFile containing the
233    * old path, and @other_file will be set to a #GFile containing the new path.
234    *
235    * In all the other cases, @other_file will be set to #NULL.
236    **/
237   signals[CHANGED] =
238     g_signal_new (I_("changed"),
239                   G_TYPE_FILE_MONITOR,
240                   G_SIGNAL_RUN_LAST,
241                   G_STRUCT_OFFSET (GFileMonitorClass, changed),
242                   NULL, NULL,
243                   NULL,
244                   G_TYPE_NONE, 3,
245                   G_TYPE_FILE, G_TYPE_FILE, G_TYPE_FILE_MONITOR_EVENT);
246
247   g_object_class_install_property (object_class,
248                                    PROP_RATE_LIMIT,
249                                    g_param_spec_int ("rate-limit",
250                                                      P_("Rate limit"),
251                                                      P_("The limit of the monitor to watch for changes, in milliseconds"),
252                                                      0, G_MAXINT,
253                                                      DEFAULT_RATE_LIMIT_MSECS,
254                                                      G_PARAM_READWRITE|
255                                                      G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
256
257   g_object_class_install_property (object_class,
258                                    PROP_CANCELLED,
259                                    g_param_spec_boolean ("cancelled",
260                                                          P_("Cancelled"),
261                                                          P_("Whether the monitor has been cancelled"),
262                                                          FALSE,
263                                                          G_PARAM_READABLE|
264                                                          G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB));
265 }
266
267 static void
268 g_file_monitor_init (GFileMonitor *monitor)
269 {
270   monitor->priv = G_TYPE_INSTANCE_GET_PRIVATE (monitor,
271                                                G_TYPE_FILE_MONITOR,
272                                                GFileMonitorPrivate);
273   monitor->priv->rate_limit_msec = DEFAULT_RATE_LIMIT_MSECS;
274   monitor->priv->rate_limiter = g_hash_table_new_full (g_file_hash, (GEqualFunc)g_file_equal,
275                                                        NULL, (GDestroyNotify) rate_limiter_free);
276   monitor->priv->context = g_main_context_ref_thread_default ();
277   g_mutex_init (&monitor->priv->mutex);
278 }
279
280 /**
281  * g_file_monitor_is_cancelled:
282  * @monitor: a #GFileMonitor
283  * 
284  * Returns whether the monitor is canceled.
285  *
286  * Returns: %TRUE if monitor is canceled. %FALSE otherwise.
287  **/
288 gboolean
289 g_file_monitor_is_cancelled (GFileMonitor *monitor)
290 {
291   gboolean res;
292
293   g_return_val_if_fail (G_IS_FILE_MONITOR (monitor), FALSE);
294
295   G_LOCK (cancelled);
296   res = monitor->priv->cancelled;
297   G_UNLOCK (cancelled);
298   
299   return res;
300 }
301
302 /**
303  * g_file_monitor_cancel:
304  * @monitor: a #GFileMonitor.
305  * 
306  * Cancels a file monitor.
307  * 
308  * Returns: %TRUE if monitor was cancelled.
309  **/
310 gboolean
311 g_file_monitor_cancel (GFileMonitor* monitor)
312 {
313   GFileMonitorClass *klass;
314   
315   g_return_val_if_fail (G_IS_FILE_MONITOR (monitor), FALSE);
316   
317   G_LOCK (cancelled);
318   if (monitor->priv->cancelled)
319     {
320       G_UNLOCK (cancelled);
321       return TRUE;
322     }
323   
324   monitor->priv->cancelled = TRUE;
325   G_UNLOCK (cancelled);
326   
327   g_object_notify (G_OBJECT (monitor), "cancelled");
328
329   klass = G_FILE_MONITOR_GET_CLASS (monitor);
330   return (* klass->cancel) (monitor);
331 }
332
333 /**
334  * g_file_monitor_set_rate_limit:
335  * @monitor: a #GFileMonitor.
336  * @limit_msecs: a non-negative integer with the limit in milliseconds
337  *     to poll for changes
338  *
339  * Sets the rate limit to which the @monitor will report
340  * consecutive change events to the same file.
341  */
342 void
343 g_file_monitor_set_rate_limit (GFileMonitor *monitor,
344                                gint          limit_msecs)
345 {
346   GFileMonitorPrivate *priv;
347
348   g_return_if_fail (G_IS_FILE_MONITOR (monitor));
349   g_return_if_fail (limit_msecs >= 0);
350
351   priv = monitor->priv;
352   if (priv->rate_limit_msec != limit_msecs)
353     {
354       monitor->priv->rate_limit_msec = limit_msecs;
355       g_object_notify (G_OBJECT (monitor), "rate-limit");
356     }
357 }
358
359 struct _FileChange {
360   GFile             *child;
361   GFile             *other_file;
362   GFileMonitorEvent  event_type;
363 };
364
365 static void
366 file_change_free (FileChange *change)
367 {
368   g_object_unref (change->child);
369   if (change->other_file)
370     g_object_unref (change->other_file);
371   
372   g_slice_free (FileChange, change);
373 }
374
375 static gboolean
376 emit_cb (gpointer data)
377 {
378   GFileMonitor *monitor = G_FILE_MONITOR (data);
379   GSList *pending, *iter;
380
381   g_mutex_lock (&monitor->priv->mutex);
382   pending = g_slist_reverse (monitor->priv->pending_file_changes);
383   monitor->priv->pending_file_changes = NULL;
384   if (monitor->priv->pending_file_change_source)
385     {
386       g_source_unref (monitor->priv->pending_file_change_source);
387       monitor->priv->pending_file_change_source = NULL;
388     }
389   g_mutex_unlock (&monitor->priv->mutex);
390
391   g_object_ref (monitor);
392   for (iter = pending; iter; iter = iter->next)
393     {
394        FileChange *change = iter->data;
395
396        g_signal_emit (monitor, signals[CHANGED], 0,
397                       change->child, change->other_file, change->event_type);
398        file_change_free (change);
399     }
400   g_slist_free (pending);
401   g_object_unref (monitor);
402
403   return FALSE;
404 }
405
406 static void
407 emit_in_idle (GFileMonitor      *monitor,
408               GFile             *child,
409               GFile             *other_file,
410               GFileMonitorEvent  event_type)
411 {
412   GSource *source;
413   FileChange *change;
414   GFileMonitorPrivate *priv;
415
416   priv = monitor->priv;
417
418   change = g_slice_new (FileChange);
419
420   change->child = g_object_ref (child);
421   if (other_file)
422     change->other_file = g_object_ref (other_file);
423   else
424     change->other_file = NULL;
425   change->event_type = event_type;
426
427   g_mutex_lock (&monitor->priv->mutex);
428   if (!priv->pending_file_change_source)
429     {
430       source = g_idle_source_new ();
431       priv->pending_file_change_source = source;
432       g_source_set_priority (source, 0);
433
434       /* We don't ref monitor here - instead dispose will free any
435        * pending idles.
436        */
437       g_source_set_callback (source, emit_cb, monitor, NULL);
438       g_source_attach (source, monitor->priv->context);
439     }
440   /* We reverse this in the processor */
441   priv->pending_file_changes = g_slist_prepend (priv->pending_file_changes, change);
442   g_mutex_unlock (&monitor->priv->mutex);
443 }
444
445 static guint32
446 get_time_msecs (void)
447 {
448   return g_get_monotonic_time () / G_TIME_SPAN_MILLISECOND;
449 }
450
451 static guint32
452 time_difference (guint32 from, guint32 to)
453 {
454   if (from > to)
455     return 0;
456   return to - from;
457 }
458
459 /* Change event rate limiting support: */
460
461 static RateLimiter *
462 new_limiter (GFileMonitor *monitor,
463              GFile             *file)
464 {
465   RateLimiter *limiter;
466
467   limiter = g_slice_new0 (RateLimiter);
468   limiter->file = g_object_ref (file);
469   g_hash_table_insert (monitor->priv->rate_limiter, file, limiter);
470   
471   return limiter;
472 }
473
474 static void
475 rate_limiter_send_virtual_changes_done_now (GFileMonitor *monitor, 
476                                             RateLimiter  *limiter)
477 {
478   if (limiter->send_virtual_changes_done_at != 0)
479     {
480       emit_in_idle (monitor, limiter->file, NULL,
481                     G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT);
482       limiter->send_virtual_changes_done_at = 0;
483     }
484 }
485
486 static void
487 rate_limiter_send_delayed_change_now (GFileMonitor *monitor, 
488                                       RateLimiter *limiter, 
489                                       guint32 time_now)
490 {
491   if (limiter->send_delayed_change_at != 0)
492     {
493       emit_in_idle (monitor, 
494                     limiter->file, NULL,
495                     G_FILE_MONITOR_EVENT_CHANGED);
496       limiter->send_delayed_change_at = 0;
497       limiter->last_sent_change_time = time_now;
498     }
499 }
500
501 typedef struct {
502   guint32 min_time;
503   guint32 time_now;
504   GFileMonitor *monitor;
505 } ForEachData;
506
507 static gboolean
508 calc_min_time (GFileMonitor *monitor, 
509                RateLimiter *limiter, 
510                guint32 time_now, 
511                guint32 *min_time)
512 {
513   gboolean delete_me;
514   guint32 expire_at;
515
516   delete_me = TRUE;
517
518   if (limiter->last_sent_change_time != 0)
519     {
520       /* Set a timeout at 2*rate limit so that we can clear out the change from the hash eventually */
521       expire_at = limiter->last_sent_change_time + 2 * monitor->priv->rate_limit_msec;
522
523       if (time_difference (time_now, expire_at) > 0)
524         {
525           delete_me = FALSE;
526           *min_time = MIN (*min_time,
527                            time_difference (time_now, expire_at));
528         }
529     }
530
531   if (limiter->send_delayed_change_at != 0)
532     {
533       delete_me = FALSE;
534       *min_time = MIN (*min_time,
535                        time_difference (time_now, limiter->send_delayed_change_at));
536     }
537
538   if (limiter->send_virtual_changes_done_at != 0)
539     {
540       delete_me = FALSE;
541       *min_time = MIN (*min_time,
542                        time_difference (time_now, limiter->send_virtual_changes_done_at));
543     }
544
545   return delete_me;
546 }
547
548 static gboolean
549 foreach_rate_limiter_fire (gpointer key,
550                            gpointer value,
551                            gpointer user_data)
552 {
553   RateLimiter *limiter = value;
554   ForEachData *data = user_data;
555
556   if (limiter->send_delayed_change_at != 0 &&
557       time_difference (data->time_now, limiter->send_delayed_change_at) == 0)
558     rate_limiter_send_delayed_change_now (data->monitor, limiter, data->time_now);
559   
560   if (limiter->send_virtual_changes_done_at != 0 &&
561       time_difference (data->time_now, limiter->send_virtual_changes_done_at) == 0)
562     rate_limiter_send_virtual_changes_done_now (data->monitor, limiter);
563   
564   return calc_min_time (data->monitor, limiter, data->time_now, &data->min_time);
565 }
566
567 static gboolean 
568 rate_limiter_timeout (gpointer timeout_data)
569 {
570   GFileMonitor *monitor = timeout_data;
571   ForEachData data;
572   GSource *source;
573   
574   data.min_time = G_MAXUINT32;
575   data.monitor = monitor;
576   data.time_now = get_time_msecs ();
577   g_hash_table_foreach_remove (monitor->priv->rate_limiter,
578                                foreach_rate_limiter_fire,
579                                &data);
580   
581   /* Remove old timeout */
582   if (monitor->priv->timeout)
583     {
584       g_source_destroy (monitor->priv->timeout);
585       g_source_unref (monitor->priv->timeout);
586       monitor->priv->timeout = NULL;
587       monitor->priv->timeout_fires_at = 0;
588     }
589   
590   /* Set up new timeout */
591   if (data.min_time != G_MAXUINT32)
592     {
593       source = g_timeout_source_new (data.min_time + 1); /* + 1 to make sure we've really passed the time */
594       g_source_set_callback (source, rate_limiter_timeout, monitor, NULL);
595       g_source_attach (source, monitor->priv->context);
596       
597       monitor->priv->timeout = source;
598       monitor->priv->timeout_fires_at = data.time_now + data.min_time; 
599     }
600   
601   return FALSE;
602 }
603
604 static gboolean
605 foreach_rate_limiter_update (gpointer key,
606                              gpointer value,
607                              gpointer user_data)
608 {
609   RateLimiter *limiter = value;
610   ForEachData *data = user_data;
611
612   return calc_min_time (data->monitor, limiter, data->time_now, &data->min_time);
613 }
614
615 static void
616 update_rate_limiter_timeout (GFileMonitor *monitor, 
617                              guint new_time)
618 {
619   ForEachData data;
620   GSource *source;
621   
622   if (monitor->priv->timeout_fires_at != 0 && new_time != 0 &&
623       time_difference (new_time, monitor->priv->timeout_fires_at) == 0)
624     return; /* Nothing to do, we already fire earlier than that */
625
626   data.min_time = G_MAXUINT32;
627   data.monitor = monitor;
628   data.time_now = get_time_msecs ();
629   g_hash_table_foreach_remove (monitor->priv->rate_limiter,
630                                foreach_rate_limiter_update,
631                                &data);
632
633   /* Remove old timeout */
634   if (monitor->priv->timeout)
635     {
636       g_source_destroy (monitor->priv->timeout);
637       g_source_unref (monitor->priv->timeout);
638       monitor->priv->timeout_fires_at = 0;
639       monitor->priv->timeout = NULL;
640     }
641
642   /* Set up new timeout */
643   if (data.min_time != G_MAXUINT32)
644     {
645       source = g_timeout_source_new (data.min_time + 1);  /* + 1 to make sure we've really passed the time */
646       g_source_set_callback (source, rate_limiter_timeout, monitor, NULL);
647       g_source_attach (source, monitor->priv->context);
648       
649       monitor->priv->timeout = source;
650       monitor->priv->timeout_fires_at = data.time_now + data.min_time; 
651     }
652 }
653
654 /**
655  * g_file_monitor_emit_event:
656  * @monitor: a #GFileMonitor.
657  * @child: a #GFile.
658  * @other_file: a #GFile.
659  * @event_type: a set of #GFileMonitorEvent flags.
660  * 
661  * Emits the #GFileMonitor::changed signal if a change
662  * has taken place. Should be called from file monitor 
663  * implementations only.
664  *
665  * The signal will be emitted from an idle handler (in the <link
666  * linkend="g-main-context-push-thread-default">thread-default main
667  * context</link>).
668  **/
669 void
670 g_file_monitor_emit_event (GFileMonitor      *monitor,
671                            GFile             *child,
672                            GFile             *other_file,
673                            GFileMonitorEvent  event_type)
674 {
675   guint32 time_now, since_last;
676   gboolean emit_now;
677   RateLimiter *limiter;
678
679   g_return_if_fail (G_IS_FILE_MONITOR (monitor));
680   g_return_if_fail (G_IS_FILE (child));
681
682   limiter = g_hash_table_lookup (monitor->priv->rate_limiter, child);
683
684   if (event_type != G_FILE_MONITOR_EVENT_CHANGED)
685     {
686       if (limiter)
687         {
688           rate_limiter_send_delayed_change_now (monitor, limiter, get_time_msecs ());
689           if (event_type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT)
690             limiter->send_virtual_changes_done_at = 0;
691           else
692             rate_limiter_send_virtual_changes_done_now (monitor, limiter);
693           update_rate_limiter_timeout (monitor, 0);
694         }
695       emit_in_idle (monitor, child, other_file, event_type);
696     }
697   else
698     {
699       /* Changed event, rate limit */
700       time_now = get_time_msecs ();
701       emit_now = TRUE;
702       
703       if (limiter)
704         {
705           since_last = time_difference (limiter->last_sent_change_time, time_now);
706           if (since_last < monitor->priv->rate_limit_msec)
707             {
708               /* We ignore this change, but arm a timer so that we can fire it later if we
709                  don't get any other events (that kill this timeout) */
710               emit_now = FALSE;
711               if (limiter->send_delayed_change_at == 0)
712                 {
713                   limiter->send_delayed_change_at = time_now + monitor->priv->rate_limit_msec;
714                   update_rate_limiter_timeout (monitor, limiter->send_delayed_change_at);
715                 }
716             }
717         }
718       
719       if (limiter == NULL)
720         limiter = new_limiter (monitor, child);
721       
722       if (emit_now)
723         {
724           emit_in_idle (monitor, child, other_file, event_type);
725           
726           limiter->last_sent_change_time = time_now;
727           limiter->send_delayed_change_at = 0;
728           /* Set a timeout of 2*rate limit so that we can clear out the change from the hash eventually */
729           update_rate_limiter_timeout (monitor, time_now + 2 * monitor->priv->rate_limit_msec);
730         }
731       
732       /* Schedule a virtual change done. This is removed if we get a real one, and
733          postponed if we get more change events. */
734       
735       limiter->send_virtual_changes_done_at = time_now + DEFAULT_VIRTUAL_CHANGES_DONE_DELAY_SECS * 1000;
736       update_rate_limiter_timeout (monitor, limiter->send_virtual_changes_done_at);
737     }
738 }