summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-30 01:52:17 +0000
committerwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-30 01:52:17 +0000
commitbd6fc540b7970acb05a998f23107dec70f35a3c0 (patch)
tree37349353ff54a9bceb544f689104d188f06ef1d4 /remoting
parent62bde744e6697d644964f18fdfd051fdb6fbf0bd (diff)
downloadchromium_src-bd6fc540b7970acb05a998f23107dec70f35a3c0.zip
chromium_src-bd6fc540b7970acb05a998f23107dec70f35a3c0.tar.gz
chromium_src-bd6fc540b7970acb05a998f23107dec70f35a3c0.tar.bz2
Restore multi-thread support to RunningAverage.
The host-side VideoScheduler records creates the RunningAverage on the caller thread, but records stats to it on the capture and encode threads and queries it on the capture thread, so currently requires a thread-safe implementation. BUG=223769 Review URL: https://chromiumcodereview.appspot.com/13154003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@191486 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/base/running_average.cc6
-rw-r--r--remoting/base/running_average.h9
2 files changed, 9 insertions, 6 deletions
diff --git a/remoting/base/running_average.cc b/remoting/base/running_average.cc
index dd7c7be..83877dc 100644
--- a/remoting/base/running_average.cc
+++ b/remoting/base/running_average.cc
@@ -18,7 +18,7 @@ RunningAverage::~RunningAverage() {
}
void RunningAverage::Record(int64 value) {
- DCHECK(CalledOnValidThread());
+ base::AutoLock auto_lock(lock_);
data_points_.push_back(value);
sum_ += value;
@@ -29,8 +29,8 @@ void RunningAverage::Record(int64 value) {
}
}
-double RunningAverage::Average() const {
- DCHECK(CalledOnValidThread());
+double RunningAverage::Average() {
+ base::AutoLock auto_lock(lock_);
if (data_points_.empty())
return 0;
diff --git a/remoting/base/running_average.h b/remoting/base/running_average.h
index 042f773..633659d 100644
--- a/remoting/base/running_average.h
+++ b/remoting/base/running_average.h
@@ -8,14 +8,14 @@
#include <deque>
#include "base/basictypes.h"
-#include "base/threading/non_thread_safe.h"
+#include "base/synchronization/lock.h"
namespace remoting {
// Calculates the average of the most recent N recorded samples.
// This is typically used to smooth out random variation in point samples
// over bandwidth, frame rate, etc.
-class RunningAverage : public base::NonThreadSafe {
+class RunningAverage {
public:
// Constructs a helper to average over the |window_size| most recent samples.
explicit RunningAverage(int window_size);
@@ -25,13 +25,16 @@ class RunningAverage : public base::NonThreadSafe {
void Record(int64 value);
// Returns the average over up to |window_size| of the most recent samples.
- double Average() const;
+ double Average();
private:
// Stores the desired window size, as size_t to avoid casting when comparing
// with the size of |data_points_|.
const size_t window_size_;
+ // Protects |data_points_| and |sum_|.
+ base::Lock lock_;
+
// Stores the |window_size| most recently recorded samples.
std::deque<int64> data_points_;