]> git.tuebingen.mpg.de Git - dss.git/commit - dss.c
Improve next_snapshot_is_due().
authorAndre Noll <maan@systemlinux.org>
Fri, 28 Aug 2009 09:12:30 +0000 (11:12 +0200)
committerAndre Noll <maan@systemlinux.org>
Fri, 28 Aug 2009 09:12:30 +0000 (11:12 +0200)
commit7c487767f42a70358eea15eb9a86ac673856f905
tree02075ccc25a26aca246fa2789c9fad963917185e
parent483c869aadfb8aafc5e02d2b1fbdfb773f798f54
Improve next_snapshot_is_due().

Currently it's a bit weird how next_snapshot_is_due() decides whether
the next snapshot time has to be (re-)computed:

On startup, next_snapshot_time is zero as it is declared
static.

next_snapshot_is_due() checks whether next_snapshot_time is
greater than the current time. If yes, then next_snapshot_time
needs not be updated and the function returns false.

Otherwise (e.g. if it is called for the first time),
next_snapshot_time is recomputed, next_snapshot_is_due()
checks again if it is greater than the current time and
returns false if it is, true otherwise.

Consequently, dss computes the next snapshot time twice per snapshot.
Moreover, it compares next_snapshot_time twice against the current time
where one comparison would suffice. The code is thus less efficient
and harder to understand than necessary. This patch addresses both
issues. It introduces the two trivial helper functions

next_snapshot_time_is_valid() and invalidate_next_snapshot_time().

The former function simply tests next_snapshot_time against zero. It
is called from next_snapshot_is_due(). If it returns false, the new
compute_next_snapshot_time() is called (which makes next_snapshot_time
valid). Next, the usual comparison against the current time is
performed.

invalidate_next_snapshot_time() sets next_snapshot_time to zero. It
is called from pre_create_hook() and from handle_sighup(), the latter
call is necessary because changes in the config file might lead to
different snapshot creation times.
dss.c