From e38f008b9b6e1a2c2c41b5bb569f65715423ae5b Mon Sep 17 00:00:00 2001 From: Oliver Schmidt Date: Wed, 30 Nov 2011 23:41:39 +0100 Subject: [PATCH] The dependency on the ucontext functions has the potential to keep others from successfully using cpu/native for other platforms. As the Contiki multithreading library typically isn't used at all it's not worth the trouble. So we just limit it to Windows and Linux - where it is known to not only build but actually work. If someone needs the Contiki cpu/native multithreading library on another platform he's certainly welcome to add that platform - hopefully by just activating the codepath that we now made exclusive for Linux for his platform. --- cpu/native/mtarch.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cpu/native/mtarch.c b/cpu/native/mtarch.c index 6121ae8ba..5bb01a0cc 100644 --- a/cpu/native/mtarch.c +++ b/cpu/native/mtarch.c @@ -40,7 +40,7 @@ static void *main_fiber; -#else /* _WIN32 || __CYGWIN__ */ +#elif defined(__linux) #include #include @@ -54,7 +54,7 @@ struct mtarch_t { static ucontext_t main_context; static ucontext_t *running_context; -#endif /* _WIN32 || __CYGWIN__ */ +#endif /* _WIN32 || __CYGWIN__ || __linux */ #include "mtarch.h" @@ -88,7 +88,7 @@ mtarch_start(struct mtarch_thread *thread, thread->mt_thread = CreateFiber(0, (LPFIBER_START_ROUTINE)function, data); -#else /* _WIN32 || __CYGWIN__ */ +#elif defined(__linux) thread->mt_thread = malloc(sizeof(struct mtarch_t)); @@ -118,7 +118,7 @@ mtarch_start(struct mtarch_thread *thread, makecontext(&((struct mtarch_t *)thread->mt_thread)->context, (void (*)(void))function, 1, data); -#endif /* _WIN32 || __CYGWIN__ */ +#endif /* _WIN32 || __CYGWIN__ || __linux */ } /*--------------------------------------------------------------------------*/ void @@ -128,11 +128,11 @@ mtarch_yield(void) SwitchToFiber(main_fiber); -#else /* _WIN32 || __CYGWIN__ */ +#elif defined(__linux) swapcontext(running_context, &main_context); -#endif /* _WIN32 || __CYGWIN__ */ +#endif /* _WIN32 || __CYGWIN__ || __linux */ } /*--------------------------------------------------------------------------*/ void @@ -142,13 +142,13 @@ mtarch_exec(struct mtarch_thread *thread) SwitchToFiber(thread->mt_thread); -#else /* _WIN32 || __CYGWIN__ */ +#elif defined(__linux) running_context = &((struct mtarch_t *)thread->mt_thread)->context; swapcontext(&main_context, running_context); running_context = NULL; -#endif /* _WIN32 || __CYGWIN__ */ +#endif /* _WIN32 || __CYGWIN__ || __linux */ } /*--------------------------------------------------------------------------*/ void @@ -158,11 +158,11 @@ mtarch_stop(struct mtarch_thread *thread) DeleteFiber(thread->mt_thread); -#else /* _WIN32 || __CYGWIN__ */ +#elif defined(linux) || defined(__linux) free(thread->mt_thread); -#endif /* _WIN32 || __CYGWIN__ */ +#endif /* _WIN32 || __CYGWIN__ || __linux */ } /*--------------------------------------------------------------------------*/ void