From 74973a93594e4150a827459708895577a795036b Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 2 Jul 2018 11:34:44 -0700 Subject: Added a threadsafe speedometer class. --- src/tests/speedometer.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/tests/speedometer.cpp (limited to 'src/tests') diff --git a/src/tests/speedometer.cpp b/src/tests/speedometer.cpp new file mode 100644 index 0000000..4532f59 --- /dev/null +++ b/src/tests/speedometer.cpp @@ -0,0 +1,51 @@ +#include +#include +#include + +#include + +class Report : public Bu::Thread +{ +public: + Report() : + sKeys( 500, 8 ) + { + } + + ~Report() + { + } + + Bu::Speedometer sKeys; + bool bRunning; + +protected: + virtual void run() + { + bRunning = true; + while( bRunning ) + { + usleep( 500000 ); +// Bu::println("Speed: %1 - %2 k/s").arg( sKeys.getTotalEvents() ). +// arg( sKeys.getSpeed() ); + } + } +}; + +int main( int argc, char *argv[] ) +{ + Report r; + + r.start(); + + for(;;) + { + getchar(); + r.sKeys.addEvent(); + r.sKeys.debug(); + } + + + return 0; +} + -- cgit v1.2.3