Commits

Anonymous committed 0a3831f

CxxUtils/clock.h src/clock.cxx
Provide a simplified clock_gettime() function for MacOSX
CxxUtils/sincosf.h src/sincosf.cxx
Provide a simple sincosf() function for MacOSX

David Quarrie

  • Participants
  • Parent commits 24b5951
  • Tags CxxUtils-00-00-50

Comments (0)

Files changed (5)

+2010-01-30  David Quarrie <David.Quarrie@cern.ch>
+
+	* Tagging CxxUtils-00-00-49.
+	* CxxUtils/clock.h: ) Provide a simplified clock_gettime() function for MacOSX
+	* src/clock.cxx:    )
+	* CxxUtils/sincosf.h: ) Provide a simple sincosf() function for MacOSX
+	* src/sincosf.cxx:    )
+	
 2010-01-14  scott snyder  <snyder@bnl.gov>
 
 	* Tagging CxxUtils-00-00-48.

File CxxUtils/clock.h

+// This file's extension implies that it's C, but it's really -*- C++ -*-.
+// $Id$
+/**
+ * @file CxxUtils/clock.h
+ * @author David Quarrie <David.Quarrie@cern.ch>
+ * @date Jan 2010, from earlier code.
+ * @brief Provide simplified clock_gettime() function for MacOSX.
+ */
+
+
+#ifndef CXXUTILS_CLOCK_H
+#define CXXUTILS_CLOCK_H
+
+#ifdef __APPLE__
+#include <time.h>
+#define CLOCK_REALTIME           0
+#define CLOCK_MONOTONIC          1
+#define CLOCK_PROCESS_CPUTIME_ID 2
+#define CLOCK_THREAD_CPUTIME_ID	 3
+
+long clock_gettime (unsigned int which_clock, struct timespec *tp);
+#endif
+
+#endif // not CXXUTILS_CLOCK_H

File CxxUtils/sincosf.h

+// This file's extension implies that it's C, but it's really -*- C++ -*-.
+// $Id$
+/**
+ * @file CxxUtils/sincosf.h
+ * @author David Quarrie <David.Quarrie@cern.ch>
+ * @date Jan 2010
+ * @brief Provide sincosf function for MacOSX.
+ */
+
+
+#ifndef CXXUTILS_SINCOSF_H
+#define CXXUTILS_SINCOSF_H
+
+#ifdef __APPLE__
+void sincosf(float x, float* sn, float* cs);
+#endif
+
+#endif // not CXXUTILS_SINCOSF_H

File src/clock.cxx

+// $Id$
+/**
+ * @file CxxUtils/src/clock.cxx
+ * @author David Quarrie <David.Quarrie@cern.ch>
+ * @date Jan, 2010
+ * @brief Implementation of clock_gettime() function for MacOSX
+ */
+
+#include "CxxUtils/clock.h"
+
+#ifdef __APPLE__
+#include <stdint.h>
+#include <mach/mach_time.h> 
+
+long clock_gettime (unsigned int which_clock, struct timespec *tp) 
+{
+	uint64_t time = 0;
+    mach_timebase_info_data_t info;
+    kern_return_t err = mach_timebase_info( &info );
+        
+	//Convert the timebase into seconds
+    if( err == 0  ) {
+		uint64_t mach_time = mach_absolute_time( );
+		time = mach_time * info.numer / info.denom; 
+	}
+	tp->tv_sec  = time * 1e-9;
+	tp->tv_nsec = time - (tp->tv_sec * 1e9);
+	return 0;
+}
+#endif

File src/sincosf.cxx

+// $Id$
+/**
+ * @file CxxUtils/src/sincosf.cxx
+ * @author David Quarrie <David.Quarrie@cern.ch>
+ * @date Jan, 2010
+ * @brief Implementation of sincosf function for MacOSX
+ */
+
+#include "CxxUtils/sincosf.h"
+#include <cmath>
+
+#ifdef __APPLE__
+void sincosf(float x, float* sn, float* cs)
+{
+	*sn = std::sin(x);
+	*cs = std::cos(x);
+}
+#endif