]> git.sesse.net Git - cubemap/blobdiff - stats.h
Factor statistics writing into its own class and file.
[cubemap] / stats.h
diff --git a/stats.h b/stats.h
new file mode 100644 (file)
index 0000000..c4fb17a
--- /dev/null
+++ b/stats.h
@@ -0,0 +1,29 @@
+#ifndef _STATS_H
+#define _STATS_H 1
+
+#include <pthread.h>
+#include <string>
+
+// A thread that regularly writes out statistics, ie. a list of all connected clients
+// with some information about each.
+
+class StatsThread {
+public:
+       StatsThread(const std::string &stats_file, int stats_interval);
+       void run();
+       void stop();
+
+private:
+       // Recover the this pointer, and call do_work().
+       static void *do_work_thunk(void *arg);
+
+       void do_work();
+
+       std::string stats_file;
+       int stats_interval;
+
+       pthread_t worker_thread;
+       volatile bool should_stop;
+};
+       
+#endif  // !defined(_STATS_H)