/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. #ifndef AWS_AVERAGING_COUNTER_H
  6. #include <AWSAveragingCounter.h>
  7. #endif
  8. AWSAveragingCounter::AWSAveragingCounter() :
  9. _value(0.0), _observations(0.0), _lock() {
  10. }
  11. AWSAveragingCounter::~AWSAveragingCounter() {
  12. }
  13. void AWSAveragingCounter::addValue(double value) {
  14. _lock.writeAcquire();
  15. _observations = _observations + 1.0;
  16. _value = (value * (1.0 / _observations)) + (_value * ((_observations - 1.0) / _observations));
  17. _lock.writeRelease();
  18. }