diff options
author | Mike Buland <mbuland@penny-arcade.com> | 2018-07-02 11:34:44 -0700 |
---|---|---|
committer | Mike Buland <mbuland@penny-arcade.com> | 2018-07-02 11:34:44 -0700 |
commit | 74973a93594e4150a827459708895577a795036b (patch) | |
tree | 9faff0701bf458144c58f9b9d29ce845dd132aeb /src/test | |
parent | 9bcbc8f919fc1c779d3b9c649dcbe3606fdbed32 (diff) | |
download | libbu++-74973a93594e4150a827459708895577a795036b.tar.gz libbu++-74973a93594e4150a827459708895577a795036b.tar.bz2 libbu++-74973a93594e4150a827459708895577a795036b.tar.xz libbu++-74973a93594e4150a827459708895577a795036b.zip |
Added a threadsafe speedometer class.
Diffstat (limited to '')
-rw-r--r-- | src/tests/speedometer.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
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 @@ | |||
1 | #include <bu/sio.h> | ||
2 | #include <bu/speedometer.h> | ||
3 | #include <bu/thread.h> | ||
4 | |||
5 | #include <unistd.h> | ||
6 | |||
7 | class Report : public Bu::Thread | ||
8 | { | ||
9 | public: | ||
10 | Report() : | ||
11 | sKeys( 500, 8 ) | ||
12 | { | ||
13 | } | ||
14 | |||
15 | ~Report() | ||
16 | { | ||
17 | } | ||
18 | |||
19 | Bu::Speedometer sKeys; | ||
20 | bool bRunning; | ||
21 | |||
22 | protected: | ||
23 | virtual void run() | ||
24 | { | ||
25 | bRunning = true; | ||
26 | while( bRunning ) | ||
27 | { | ||
28 | usleep( 500000 ); | ||
29 | // Bu::println("Speed: %1 - %2 k/s").arg( sKeys.getTotalEvents() ). | ||
30 | // arg( sKeys.getSpeed() ); | ||
31 | } | ||
32 | } | ||
33 | }; | ||
34 | |||
35 | int main( int argc, char *argv[] ) | ||
36 | { | ||
37 | Report r; | ||
38 | |||
39 | r.start(); | ||
40 | |||
41 | for(;;) | ||
42 | { | ||
43 | getchar(); | ||
44 | r.sKeys.addEvent(); | ||
45 | r.sKeys.debug(); | ||
46 | } | ||
47 | |||
48 | |||
49 | return 0; | ||
50 | } | ||
51 | |||