summaryrefslogtreecommitdiffstats
path: root/libdimension/platform.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2010-06-29 21:17:39 -0600
committerTavian Barnes <tavianator@gmail.com>2010-06-29 21:17:39 -0600
commit1874938c0d35990f95e494a7fef066bf97001d8f (patch)
treeb6c43254129237843d07f7cbf13572397e6973f6 /libdimension/platform.c
parenteb4691098767935c1ffd10f7da46796c11eefcfa (diff)
downloaddimension-1874938c0d35990f95e494a7fef066bf97001d8f.tar.xz
Move platform-specific stuff in libdimension into platform.c.
Diffstat (limited to 'libdimension/platform.c')
-rw-r--r--libdimension/platform.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/libdimension/platform.c b/libdimension/platform.c
index 6ac15c0..be7e7a8 100644
--- a/libdimension/platform.c
+++ b/libdimension/platform.c
@@ -19,8 +19,37 @@
*************************************************************************/
#include "dimension_impl.h"
-#include <unistd.h> /* For sysconf() */
-#include <sched.h> /* For sched_getaffinity() */
+#include <unistd.h> /* For sysconf() */
+#include <arpa/inet.h> /* For htonl() */
+#include <execinfo.h> /* For backtrace() etc. */
+#include <sys/syscall.h> /* For gettid() where supported */
+#include <sched.h> /* For sched_getaffinity() */
+
+void
+dmnsn_backtrace(FILE *file)
+{
+ const size_t size = 128;
+ void *buffer[size];
+
+ int nptrs = backtrace(buffer, size);
+ backtrace_symbols_fd(buffer, nptrs, fileno(file));
+}
+
+bool
+dmnsn_is_main_thread()
+{
+#ifdef SYS_gettid
+ return getpid() == syscall(SYS_gettid);
+#else
+ return true;
+#endif
+}
+
+bool
+dmnsn_is_little_endian()
+{
+ return htonl(1) != 1;
+}
size_t
dmnsn_ncpus()