summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--make/build-jogl.xml4
-rw-r--r--src/jogl/native/timespec.c63
-rw-r--r--src/jogl/native/timespec.h19
3 files changed, 86 insertions, 0 deletions
diff --git a/make/build-jogl.xml b/make/build-jogl.xml
index fc6786e21..511f147be 100644
--- a/make/build-jogl.xml
+++ b/make/build-jogl.xml
@@ -1130,6 +1130,8 @@
<linker id="linker.cfg.macosx.jogl" extends="linker.cfg.macosx">
<linkerarg value="-framework" />
+ <linkerarg value="QuartzCore" />
+ <linkerarg value="-framework" />
<linkerarg value="Cocoa" />
<linkerarg value="-framework" />
<linkerarg value="OpenGL" />
@@ -1276,6 +1278,7 @@
<patternset id="c.src.files.jogl.desktop">
<include name="${rootrel.src.c}/JoglCommon.c"/>
<include name="${rootrel.src.c}/GLDebugMessageHandler.c"/>
+ <include name="${rootrel.src.c}/timespec.c" if="isOSX"/> <!-- currently only used for OSX -->
<include name="${rootrel.src.c}/macosx/MacOSXCustomCGLCode.c" if="isOSX"/>
<include name="${rootrel.src.c}/macosx/MacOSXWindowSystemInterface.m" if="isOSX"/>
<include name="${rootrel.src.c}/macosx/MacOSXWindowSystemInterface-pbuffer.m" if="isOSX"/>
@@ -1350,6 +1353,7 @@
<includepath path="stub_includes/cg" if="setup.addNativeNVidiaCG"/>
<!-- This is for the generated headers for handwritten C code -->
+ <includepath path="${src.c}"/>
<includepath path="${src.generated.c}" />
<includepath path="${src.generated.c}/X11" if="isX11"/>
<includepath path="${src.generated.c}/MacOSX" if="isOSX"/>
diff --git a/src/jogl/native/timespec.c b/src/jogl/native/timespec.c
new file mode 100644
index 000000000..74c1a6901
--- /dev/null
+++ b/src/jogl/native/timespec.c
@@ -0,0 +1,63 @@
+#include "timespec.h"
+#include <sys/time.h>
+
+void timespec_now(struct timespec *ts)
+{
+ struct timeval tv;
+
+ // not using clock_gettime() [of rt library] due to portability
+ gettimeofday(&tv, NULL);
+ ts->tv_sec = tv.tv_sec;
+ ts->tv_nsec = tv.tv_usec*1000;
+}
+
+void timespec_addms(struct timespec *ts, long ms)
+{
+ int sec=ms/1000;
+ ms=ms-sec*1000;
+
+ // perform the addition
+ ts->tv_nsec+=ms*1000000;
+
+ // adjust the time
+ ts->tv_sec+=ts->tv_nsec/1000000000 + sec;
+ ts->tv_nsec=ts->tv_nsec%1000000000;
+}
+
+void timespec_addns(struct timespec *ts, long ns)
+{
+ int sec=ns/1000000000;
+ ns=ns - sec*1000000000;
+
+ // perform the addition
+ ts->tv_nsec+=ns;
+
+ // adjust the time
+ ts->tv_sec+=ts->tv_nsec/1000000000 + sec;
+ ts->tv_nsec=ts->tv_nsec%1000000000;
+
+}
+
+int timespec_compare(struct timespec *a, struct timespec *b)
+{
+ if (a->tv_sec!=b->tv_sec)
+ return a->tv_sec-b->tv_sec;
+ return a->tv_nsec-b->tv_nsec;
+}
+
+void timespec_subtract(struct timespec *r, struct timespec *a, struct timespec *b)
+{
+ r->tv_sec = a->tv_sec;
+ r->tv_nsec = a->tv_nsec - b->tv_nsec;
+ if (r->tv_nsec < 0) {
+ // borrow.
+ r->tv_nsec += 1000000000;
+ r->tv_sec --;
+ }
+ r->tv_sec = r->tv_sec - b->tv_sec;
+}
+
+long timespec_milliseconds(struct timespec *a)
+{
+ return a->tv_sec*1000 + a->tv_nsec/1000000;
+}
diff --git a/src/jogl/native/timespec.h b/src/jogl/native/timespec.h
new file mode 100644
index 000000000..671eb4716
--- /dev/null
+++ b/src/jogl/native/timespec.h
@@ -0,0 +1,19 @@
+#ifndef _timespec_h
+#define _timespec_h
+
+#include <time.h>
+
+void timespec_now(struct timespec *ts);
+void timespec_addms(struct timespec *ts, long ms);
+void timespec_addns(struct timespec *ts, long ns);
+
+/** returns 0: a==b, >0: a>b, <0: a<b */
+int timespec_compare(struct timespec *a, struct timespec *b);
+
+/** computes r = a - b */
+void timespec_subtract(struct timespec *r, struct timespec *a, struct timespec *b);
+
+/** convert the timespec into milliseconds (may overflow) */
+long timespec_milliseconds(struct timespec *a);
+
+#endif /* _timespec_h */