From 9ff6a3d031d2ffaf2863e2a866f7a96ed7ddd029 Mon Sep 17 00:00:00 2001 From: Michael Bebenita Date: Mon, 9 Aug 2010 07:42:06 -0700 Subject: [PATCH] Added class to abstract away platform specific thread primitives. --- src/Makefile | 6 ++++-- src/rt/sync/sync.cpp | 12 ++++++++++++ src/rt/sync/sync.h | 9 +++++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/rt/sync/sync.cpp create mode 100644 src/rt/sync/sync.h diff --git a/src/Makefile b/src/Makefile index 1d79a46700a..f8c891c2154 100644 --- a/src/Makefile +++ b/src/Makefile @@ -245,7 +245,8 @@ BOOT_CMXS := $(BOOT_MLS:.ml=.cmx) BOOT_OBJS := $(BOOT_MLS:.ml=.o) BOOT_CMIS := $(BOOT_MLS:.ml=.cmi) -RUNTIME_CS := rt/sync/spin_lock.cpp \ +RUNTIME_CS := rt/sync/sync.cpp \ + rt/sync/spin_lock.cpp \ rt/sync/lock_free_queue.cpp \ rt/sync/condition_variable.cpp \ rt/rust.cpp \ @@ -279,7 +280,8 @@ RUNTIME_HDR := rt/globals.h \ rt/rust_message.h \ rt/circular_buffer.h \ rt/util/array_list.h \ - rt/util/hash_map.h + rt/util/hash_map.h \ + rt/sync/sync.h RUNTIME_INCS := -Irt/isaac -Irt/uthash RUNTIME_OBJS := $(RUNTIME_CS:.cpp=$(CFG_OBJ_SUFFIX)) diff --git a/src/rt/sync/sync.cpp b/src/rt/sync/sync.cpp new file mode 100644 index 00000000000..eba51a49dfc --- /dev/null +++ b/src/rt/sync/sync.cpp @@ -0,0 +1,12 @@ +#include "../globals.h" +#include "sync.h" + +void sync::yield() { +#ifdef __APPLE__ + pthread_yield_np(); +#elif __WIN32__ + +#else + pthread_yield(); +#endif +} diff --git a/src/rt/sync/sync.h b/src/rt/sync/sync.h new file mode 100644 index 00000000000..902b5661be4 --- /dev/null +++ b/src/rt/sync/sync.h @@ -0,0 +1,9 @@ +#ifndef SYNC_H +#define SYNC_H + +class sync { +public: + static void yield(); +}; + +#endif /* SYNC_H */