reduce number of calls to gettimeofday

This commit is contained in:
Andrzej Rybczak
2012-09-07 23:11:40 +02:00
parent 89d3bd884f
commit 45a097a45b
8 changed files with 22 additions and 19 deletions

View File

@@ -223,6 +223,7 @@ void Action::Seek()
{
using Global::wHeader;
using Global::wFooter;
using Global::Timer;
using Global::SeekingInProgress;
if (!Mpd.GetTotalTime())
@@ -235,7 +236,7 @@ void Action::Seek()
LockStatusbar();
int songpos = Mpd.GetElapsedTime();
time_t t = time(0);
timeval t = Timer;
int old_timeout = wFooter->getTimeout();
wFooter->setTimeout(500);
@@ -246,7 +247,7 @@ void Action::Seek()
TraceMpdStatus();
myPlaylist->UpdateTimer();
int howmuch = Config.incremental_seeking ? (myPlaylist->Timer()-t)/2+Config.seek_time : Config.seek_time;
int howmuch = Config.incremental_seeking ? (Timer.tv_sec-t.tv_sec)/2+Config.seek_time : Config.seek_time;
Key input = Key::read(*wFooter);
auto k = Bindings.get(input);

View File

@@ -132,10 +132,7 @@ void Clock::Update()
myPlaylist->SwitchTo();
}
static timeval past = { 0, 0 };
gettimeofday(&past, 0);
tm *time = localtime(&past.tv_sec);
tm *time = localtime(&Global::Timer.tv_sec);
mask = 0;
Set(time->tm_sec % 10, 0);

View File

@@ -237,7 +237,7 @@ int main(int argc, char **argv)
)
{
DrawHeader();
gettimeofday(&past, 0);
past = Timer;
}
// header stuff end

View File

@@ -420,6 +420,11 @@ void Playlist::EnableHighlighting()
UpdateTimer();
}
void Playlist::UpdateTimer()
{
itsTimer = Global::Timer;
}
bool Playlist::SortingInProgress()
{
return w == SortDialog;

View File

@@ -76,8 +76,8 @@ class Playlist : public Screen<NC::Window>, public Filterable, public HasSongs,
bool SortingInProgress();
void EnableHighlighting();
void UpdateTimer() { time(&itsTimer); }
time_t Timer() const { return itsTimer; }
void UpdateTimer();
timeval Timer() const { return itsTimer; }
bool Add(const MPD::Song &s, bool play, int position = -1);
bool Add(const MPD::SongList &l, bool play, int position = -1);
@@ -114,7 +114,7 @@ class Playlist : public Screen<NC::Window>, public Filterable, public HasSongs,
size_t itsRemainingTime;
size_t itsScrollBegin;
time_t itsTimer;
timeval itsTimer;
};
extern Playlist *myPlaylist;

View File

@@ -95,7 +95,7 @@ void ServerInfo::Update()
static timeval past = { 0, 0 };
if (Global::Timer.tv_sec <= past.tv_sec)
return;
gettimeofday(&past, 0);
past = Global::Timer;
MPD::Statistics stats = Mpd.getStatistics();
if (stats.empty())

View File

@@ -52,7 +52,7 @@ using Global::VolumeState;
namespace
{
time_t time_of_statusbar_lock;
timeval time_of_statusbar_lock;
int lock_statusbar_delay = -1;
bool block_statusbar_update = 0;
@@ -145,7 +145,7 @@ void TraceMpdStatus()
{
if (!Mpd.SupportsIdle())
{
gettimeofday(&past, 0);
past = Timer;
}
else if (Config.display_bitrate && Global::Timer.tv_sec > past.tv_sec && Mpd.isPlaying())
{
@@ -153,7 +153,7 @@ void TraceMpdStatus()
// idle mode so current song's bitrate is never updated.
// we need to force ncmpcpp to fetch it.
Mpd.OrderDataFetching();
gettimeofday(&past, 0);
past = Timer;
}
Mpd.UpdateStatus();
}
@@ -161,17 +161,17 @@ void TraceMpdStatus()
ApplyToVisibleWindows(&BasicScreen::Update);
if (isVisible(myPlaylist) && myPlaylist->ActiveWindow() == myPlaylist->Items
&& Timer.tv_sec == myPlaylist->Timer()+Config.playlist_disable_highlight_delay
&& Timer.tv_sec == myPlaylist->Timer().tv_sec+Config.playlist_disable_highlight_delay
&& myPlaylist->Items->isHighlighted()
&& Config.playlist_disable_highlight_delay)
{
myPlaylist->Items->setHighlighting(0);
myPlaylist->Items->setHighlighting(false);
myPlaylist->Items->refresh();
}
if (lock_statusbar_delay > 0)
{
if (Timer.tv_sec >= time_of_statusbar_lock+lock_statusbar_delay)
if (Timer.tv_sec >= time_of_statusbar_lock.tv_sec+lock_statusbar_delay)
{
lock_statusbar_delay = -1;
@@ -709,7 +709,7 @@ void ShowMessage(const char *format, ...)
{
if (Global::ShowMessages && allow_statusbar_unlock)
{
time(&time_of_statusbar_lock);
time_of_statusbar_lock = Global::Timer;
lock_statusbar_delay = Config.message_delay_time;
if (Config.statusbar_visibility)
block_statusbar_update = 1;

View File

@@ -123,7 +123,7 @@ void Visualizer::Update()
Mpd.DisableOutput(itsOutputID);
usleep(50000);
Mpd.EnableOutput(itsOutputID);
gettimeofday(&itsTimer, 0);
itsTimer = Global::Timer;
}
void (Visualizer::*draw)(int16_t *, ssize_t, size_t, size_t);