edits
[iotcloud.git] / version2 / src / C / TimingSingleton.h
index a6e1aac5cd9cd7f4d1a60dd3276cf89121a932de..c9189c2f8a887a6417bc709517aa921523856cd4 100644 (file)
@@ -1,32 +1,39 @@
-
+#ifndef TIMINGSINGLETON_H
+#define TIMINGSINGLETON_H
+#include <sys/time.h>
 
 class TimingSingleton {
-    private static TimingSingleton singleton = new TimingSingleton( );
-    private static int64_t startTime = 0;
-
-    private static int64_t totalTime = 0;
-
-    private TimingSingleton() {
-
-    }
-
-    public static TimingSingleton getInstance( ) {
-        return singleton;
-    }
-
-
-    public static void startTime( ) {
-        startTime = System.nanoTime();
-    }
-
-    public static void endTime( ) {
-        totalTime += System.nanoTime() - startTime;
-
-    }
-
-    public static int64_t getTime( ) {
-        return totalTime;
-    }
-
-
+private:
+       int64_t fldstartTime;
+       int64_t fldtotalTime;
+
+public:
+       TimingSingleton() : fldstartTime(0),
+               fldtotalTime(0) {
+       }
+
+       int64_t nanoTime() {
+               int64_t time;
+               struct timeval tv;
+               gettimeofday(&tv, NULL);
+               return tv.tv_sec * 1000000000 + tv.tv_usec * 1000;
+       }
+
+       void startTime() {
+               fldstartTime = nanoTime();
+       }
+
+       void endTime() {
+               fldtotalTime += nanoTime() - fldstartTime;
+       }
+
+       int64_t getTime() {
+               return fldtotalTime;
+       }
+};
+
+TimingSingleton t_singleton;
+TimingSingleton *TimingSingleton_getInstance() {
+       return &t_singleton;
 }
+#endif