mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-23 20:03:31 +01:00
Move consdiffmgr_rescan() into a mainloop event.
The change here was very simple, since there is a flag set whenever we want to schedule this event. Closes ticket 25391. m
This commit is contained in:
parent
33cba1195b
commit
8a81a70878
9
changes/ticket25931
Normal file
9
changes/ticket25931
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
o Minor features (mainloop):
|
||||||
|
- Move responsibility for
|
||||||
|
rescanning the consensus cache
|
||||||
|
from a once-per-second callback to a callback that is only scheduled as
|
||||||
|
needed. Once enough items are removed from our once-per-second
|
||||||
|
callback, we can eliminate it entirely to conserve CPU when idle.
|
||||||
|
Closes ticket:
|
||||||
|
25931.
|
||||||
|
|
@ -99,6 +99,14 @@ static const compress_method_t compress_diffs_with[] = {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event for rescanning the cache.
|
||||||
|
*/
|
||||||
|
static mainloop_event_t *consdiffmgr_rescan_ev = NULL;
|
||||||
|
|
||||||
|
static void consdiffmgr_rescan_cb(mainloop_event_t *ev, void *arg);
|
||||||
|
static void mark_cdm_cache_dirty(void);
|
||||||
|
|
||||||
/** How many different methods will we try to use for diff compression? */
|
/** How many different methods will we try to use for diff compression? */
|
||||||
STATIC unsigned
|
STATIC unsigned
|
||||||
n_diff_compression_methods(void)
|
n_diff_compression_methods(void)
|
||||||
@ -372,7 +380,9 @@ cdm_cache_init(void)
|
|||||||
} else {
|
} else {
|
||||||
consdiffmgr_set_cache_flags();
|
consdiffmgr_set_cache_flags();
|
||||||
}
|
}
|
||||||
cdm_cache_dirty = 1;
|
consdiffmgr_rescan_ev =
|
||||||
|
mainloop_event_postloop_new(consdiffmgr_rescan_cb, NULL);
|
||||||
|
mark_cdm_cache_dirty();
|
||||||
cdm_cache_loaded = 0;
|
cdm_cache_loaded = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1095,6 +1105,24 @@ consdiffmgr_rescan(void)
|
|||||||
cdm_cache_dirty = 0;
|
cdm_cache_dirty = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Callback wrapper for consdiffmgr_rescan */
|
||||||
|
static void
|
||||||
|
consdiffmgr_rescan_cb(mainloop_event_t *ev, void *arg)
|
||||||
|
{
|
||||||
|
(void)ev;
|
||||||
|
(void)arg;
|
||||||
|
consdiffmgr_rescan();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Mark the cache as dirty, and schedule a rescan event. */
|
||||||
|
static void
|
||||||
|
mark_cdm_cache_dirty(void)
|
||||||
|
{
|
||||||
|
cdm_cache_dirty = 1;
|
||||||
|
tor_assert(consdiffmgr_rescan_ev);
|
||||||
|
mainloop_event_activate(consdiffmgr_rescan_ev);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper: compare two files by their from-valid-after and valid-after labels,
|
* Helper: compare two files by their from-valid-after and valid-after labels,
|
||||||
* trying to sort in ascending order by from-valid-after (when present) and
|
* trying to sort in ascending order by from-valid-after (when present) and
|
||||||
@ -1219,6 +1247,7 @@ consdiffmgr_free_all(void)
|
|||||||
memset(latest_consensus, 0, sizeof(latest_consensus));
|
memset(latest_consensus, 0, sizeof(latest_consensus));
|
||||||
consensus_cache_free(cons_diff_cache);
|
consensus_cache_free(cons_diff_cache);
|
||||||
cons_diff_cache = NULL;
|
cons_diff_cache = NULL;
|
||||||
|
mainloop_event_free(consdiffmgr_rescan_ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =====
|
/* =====
|
||||||
@ -1750,7 +1779,7 @@ consensus_compress_worker_replyfn(void *work_)
|
|||||||
compress_consensus_with,
|
compress_consensus_with,
|
||||||
job->out,
|
job->out,
|
||||||
"consensus");
|
"consensus");
|
||||||
cdm_cache_dirty = 1;
|
mark_cdm_cache_dirty();
|
||||||
|
|
||||||
unsigned u;
|
unsigned u;
|
||||||
consensus_flavor_t f = job->flavor;
|
consensus_flavor_t f = job->flavor;
|
||||||
|
@ -1730,12 +1730,6 @@ run_scheduled_events(time_t now)
|
|||||||
/* 11b. check pending unconfigured managed proxies */
|
/* 11b. check pending unconfigured managed proxies */
|
||||||
if (!net_is_disabled() && pt_proxies_configuration_pending())
|
if (!net_is_disabled() && pt_proxies_configuration_pending())
|
||||||
pt_configure_remaining_proxies();
|
pt_configure_remaining_proxies();
|
||||||
|
|
||||||
/* 12. launch diff computations. (This is free if there are none to
|
|
||||||
* launch.) */
|
|
||||||
if (dir_server_mode(options)) {
|
|
||||||
consdiffmgr_rescan();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Periodic callback: rotate the onion keys after the period defined by the
|
/* Periodic callback: rotate the onion keys after the period defined by the
|
||||||
|
Loading…
Reference in New Issue
Block a user