more edits
[iotcloud.git] / version2 / src / C / TimingSingleton.h
index a6e1aac5cd9cd7f4d1a60dd3276cf89121a932de..4983f81a16032b94ec1f1e3bce9e866730c7b3f8 100644 (file)
@@ -1,32 +1,40 @@
-
+#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:
+       static TimingSingleton singleton = new TimingSingleton( );
+       int64_t startTime = 0;
+       int64_t totalTime = 0;
+       
+ TimingSingleton() : startTime(0),
+               totalTime(0) {
+       }
+
+       int64_t nanoTime() {
+               int64_t time;
+               struct timeval tv;
+               gettimeofday(&tv, NULL);
+               return tv.tv_sec*1000000000+tv.tv_usec*1000;
+       }
+       
+ public:
+       void startTime() {
+               startTime = nanoTime();
+       }
+       
+       void endTime() {
+               totalTime += nanoTime() - startTime;
+       }
+
+       int64_t getTime() {
+               return totalTime;
+       }
+};
+
+TimingSingleton t_singleton;
+TimingSingleton * TimingSingleton_getInstance() {
+       return &t_singleton;
 }
+#endif