X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Flib%2Fevent_history.cc;h=fca88aaf18a8b6a769d7a5fcb9cb9494d6ffa709;hb=037b18b34e3e3fd9b9e692d85f35de17ab67aff8;hp=eb3438aaba1397b747554b31b25d21e4b92c8c4e;hpb=6a11232620e0006f6a2b1e8d2b56e56d84229d5c;p=dcpomatic.git diff --git a/src/lib/event_history.cc b/src/lib/event_history.cc index eb3438aab..fca88aaf1 100644 --- a/src/lib/event_history.cc +++ b/src/lib/event_history.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2017 Carl Hetherington + Copyright (C) 2017-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -18,22 +18,28 @@ */ + #include "event_history.h" #include "util.h" #include + +using boost::optional; + + EventHistory::EventHistory (int size) : _size (size) { } -float + +optional EventHistory::rate () const { boost::mutex::scoped_lock lock (_mutex); - if (int (_history.size()) < _size) { - return 0; + if (int(_history.size()) < _size) { + return {}; } struct timeval now; @@ -42,6 +48,7 @@ EventHistory::rate () const return _size / (seconds (now) - seconds (_history.back ())); } + void EventHistory::event () { @@ -50,7 +57,7 @@ EventHistory::event () struct timeval tv; gettimeofday (&tv, 0); _history.push_front (tv); - if (int (_history.size()) > _size) { + if (int(_history.size()) > _size) { _history.pop_back (); } }