reduce number of calls to gettimeofday

master
Andrzej Rybczak 14 years ago
parent 89d3bd884f
commit 45a097a45b
  1. 5
      src/actions.cpp
  2. 5
      src/clock.cpp
  3. 2
      src/ncmpcpp.cpp
  4. 5
      src/playlist.cpp
  5. 6
      src/playlist.h
  6. 2
      src/server_info.cpp
  7. 14
      src/status.cpp
  8. 2
      src/visualizer.cpp

@ -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);

@ -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);

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

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

@ -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;

@ -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())

@ -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;

@ -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);

Loading…
Cancel
Save