aboutsummaryrefslogtreecommitdiff
path: root/src/benchmarks/fred.h
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2019-01-15 15:53:45 +0100
committerFlorian Fischer <florian.fl.fischer@fau.de>2019-01-15 18:29:26 +0100
commit259fd2a64bf114907017fe286702218cdf13c8ca (patch)
treec018a3e1f7c6dfaab121f23ce25514d91eef4e93 /src/benchmarks/fred.h
parentf7e5eef592b2a70313bb0fac5f2e3ee42bd9f634 (diff)
downloadallocbench-259fd2a64bf114907017fe286702218cdf13c8ca.tar.gz
allocbench-259fd2a64bf114907017fe286702218cdf13c8ca.zip
move source code to src/
Diffstat (limited to 'src/benchmarks/fred.h')
-rw-r--r--src/benchmarks/fred.h97
1 files changed, 97 insertions, 0 deletions
diff --git a/src/benchmarks/fred.h b/src/benchmarks/fred.h
new file mode 100644
index 0000000..b0198a7
--- /dev/null
+++ b/src/benchmarks/fred.h
@@ -0,0 +1,97 @@
+// -*- C++ -*-
+
+#ifndef HL_FRED_H
+#define HL_FRED_H
+
+/// A thread-wrapper of childlike simplicity :).
+
+#if defined(_WIN32)
+
+ #include <windows.h>
+ #include <process.h>
+
+#elif defined(__SVR4)
+
+ #include <thread.h>
+ #include <pthread.h>
+ #include <unistd.h>
+
+#else
+
+ #include <pthread.h>
+ #include <unistd.h>
+
+#endif
+
+typedef void * (*ThreadFunctionType) (void *);
+
+namespace HL {
+
+class Fred {
+public:
+
+ Fred() {
+#if !defined(_WIN32)
+ pthread_attr_init (&attr);
+ pthread_attr_setscope (&attr, PTHREAD_SCOPE_SYSTEM);
+#endif
+ }
+
+ ~Fred() {
+#if !defined(_WIN32)
+ pthread_attr_destroy (&attr);
+#endif
+ }
+
+ void create (ThreadFunctionType function, void * arg) {
+#if defined(_WIN32)
+ t = CreateThread (0, 0, (LPTHREAD_START_ROUTINE) *function, (LPVOID) arg, 0, 0);
+#else
+ pthread_create (&t, &attr, function, arg);
+#endif
+ }
+
+ void join (void) {
+#if defined(_WIN32)
+ WaitForSingleObject (t, INFINITE);
+#else
+ pthread_join (t, NULL);
+#endif
+ }
+
+ static void yield (void) {
+#if defined(_WIN32)
+ Sleep (0);
+#elif defined(__SVR4)
+ thr_yield();
+#else
+ sched_yield();
+#endif
+ }
+
+
+ static void setConcurrency (int n) {
+#if defined(_WIN32)
+#elif defined(__SVR4)
+ thr_setconcurrency (n);
+#else
+ pthread_setconcurrency (n);
+#endif
+ }
+
+
+private:
+#if defined(_WIN32)
+ typedef HANDLE FredType;
+#else
+ typedef pthread_t FredType;
+ pthread_attr_t attr;
+#endif
+
+ FredType t;
+};
+
+}
+
+
+#endif