PageRenderTime 33ms CodeModel.GetById 26ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/http_server/stack/counters/AWSAveragingCounter.cpp

http://github.com/jtblatt/duderino
C++ | 26 lines | 14 code | 8 blank | 4 comment | 0 complexity | 4c519772be8ba6d71576d91205bec204 MD5 | raw file
 1/* Copyright (c) 2009 Yahoo! Inc.  All rights reserved.
 2 * The copyrights embodied in the content of this file are licensed by Yahoo! Inc.
 3 * under the BSD (revised) open source license.
 4 */
 5
 6#ifndef AWS_AVERAGING_COUNTER_H
 7#include <AWSAveragingCounter.h>
 8#endif
 9
10AWSAveragingCounter::AWSAveragingCounter() :
11    _value(0.0), _observations(0.0), _lock() {
12}
13
14AWSAveragingCounter::~AWSAveragingCounter() {
15}
16
17void AWSAveragingCounter::addValue(double value) {
18    _lock.writeAcquire();
19
20    _observations = _observations + 1.0;
21
22    _value = (value * (1.0 / _observations)) + (_value * ((_observations - 1.0) / _observations));
23
24    _lock.writeRelease();
25}
26