StateFile: schedule timer only after a change

Save the state file 2 minutes after the last change.  This reduces the
disruptions by an idle MPD, and MPD can be paged out permanently until
it is used.
This commit is contained in:
Max Kellermann 2013-04-08 22:31:51 +02:00
parent 96882175f1
commit dca1115196
4 changed files with 15 additions and 18 deletions

2
NEWS
View File

@ -13,7 +13,7 @@ ver 0.18 (2012/??/??)
- new option "tags" may be used to disable sending tags to output - new option "tags" may be used to disable sending tags to output
- alsa: workaround for noise after manual song change - alsa: workaround for noise after manual song change
* improved decoder/output error reporting * improved decoder/output error reporting
* eliminate timer wakeup on idle MPD
ver 0.17.4 (2013/??/??) ver 0.17.4 (2013/??/??)
* protocol: * protocol:

View File

@ -347,6 +347,9 @@ idle_event_emitted(void)
unsigned flags = idle_get(); unsigned flags = idle_get();
if (flags != 0) if (flags != 0)
client_list->IdleAdd(flags); client_list->IdleAdd(flags);
if (flags & (IDLE_PLAYLIST|IDLE_PLAYER|IDLE_MIXER|IDLE_OUTPUT))
state_file->CheckModified();
} }
/** /**

View File

@ -41,7 +41,6 @@ StateFile::StateFile(Path &&_path, const char *_path_utf8,
prev_volume_version(0), prev_output_version(0), prev_volume_version(0), prev_output_version(0),
prev_playlist_version(0) prev_playlist_version(0)
{ {
ScheduleSeconds(5 * 60);
} }
void void
@ -110,24 +109,16 @@ StateFile::Read()
RememberVersions(); RememberVersions();
} }
inline void void
StateFile::AutoWrite() StateFile::CheckModified()
{ {
if (!IsModified()) if (!IsActive() && IsModified())
/* nothing has changed - don't save the state file, ScheduleSeconds(2 * 60);
don't spin up the hard disk */
return;
Write();
} }
/**
* This function is called every 5 minutes by the GLib main loop, and
* saves the state file.
*/
bool bool
StateFile::OnTimeout() StateFile::OnTimeout()
{ {
AutoWrite(); Write();
return true; return false;
} }

View File

@ -48,6 +48,11 @@ public:
void Read(); void Read();
void Write(); void Write();
/**
* Schedules a write if MPD's state was modified.
*/
void CheckModified();
private: private:
/** /**
* Save the current state versions for use with IsModified(). * Save the current state versions for use with IsModified().
@ -61,8 +66,6 @@ private:
gcc_pure gcc_pure
bool IsModified() const; bool IsModified() const;
void AutoWrite();
/* virtual methods from TimeoutMonitor */ /* virtual methods from TimeoutMonitor */
virtual bool OnTimeout() override; virtual bool OnTimeout() override;
}; };