aboutsummaryrefslogtreecommitdiffstats
path: root/src/state_file.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-10-08 15:22:39 +0200
committerMax Kellermann <max@duempel.org>2009-10-08 15:22:39 +0200
commitecb118f1edab572a904890eddafd3b11c0a79a79 (patch)
tree4e273cd64778fcff80250b3b33ffb050a257c981 /src/state_file.c
parent1e663b186998ffdeef9b3b9775558e9378bad342 (diff)
downloadmpd-ecb118f1edab572a904890eddafd3b11c0a79a79.tar.gz
mpd-ecb118f1edab572a904890eddafd3b11c0a79a79.tar.xz
mpd-ecb118f1edab572a904890eddafd3b11c0a79a79.zip
state_file: save only if something has changed
If nothing has changed since the last save, don't save the state file. Saving will spin up the hard drive, which is undesirable on hosts where MPD is idling in background.
Diffstat (limited to '')
-rw-r--r--src/state_file.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/state_file.c b/src/state_file.c
index 14c76d739..4ba157b14 100644
--- a/src/state_file.c
+++ b/src/state_file.c
@@ -36,6 +36,13 @@ static char *state_file_path;
/** the GLib source id for the save timer */
static guint save_state_source_id;
+/**
+ * These version numbers determine whether we need to save the state
+ * file. If nothing has changed, we won't let the hard drive spin up.
+ */
+static unsigned prev_volume_version, prev_output_version,
+ prev_playlist_version;
+
static void
state_file_write(void)
{
@@ -57,6 +64,10 @@ state_file_write(void)
playlist_state_save(fp, &g_playlist);
while(fclose(fp) && errno == EINTR) /* nothing */;
+
+ prev_volume_version = sw_volume_state_get_hash();
+ prev_output_version = audio_output_state_get_version();
+ prev_playlist_version = playlist_state_get_hash(&g_playlist);
}
static void
@@ -88,6 +99,10 @@ state_file_read(void)
}
while(fclose(fp) && errno == EINTR) /* nothing */;
+
+ prev_volume_version = sw_volume_state_get_hash();
+ prev_output_version = audio_output_state_get_version();
+ prev_playlist_version = playlist_state_get_hash(&g_playlist);
}
/**
@@ -97,6 +112,13 @@ state_file_read(void)
static gboolean
timer_save_state_file(G_GNUC_UNUSED gpointer data)
{
+ if (prev_volume_version == sw_volume_state_get_hash() &&
+ prev_output_version == audio_output_state_get_version() &&
+ prev_playlist_version == playlist_state_get_hash(&g_playlist))
+ /* nothing has changed - don't save the state file,
+ don't spin up the hard disk */
+ return true;
+
state_file_write();
return true;
}