Bump version to 3.12
[maemo-rb.git] / firmware / asm / thread-win32.c
blob9125819ade4017946f2174484b361988b7ac2189
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2010 by Thomas Martitz
12 * Generic ARM threading support
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
25 #include <windows.h>
26 #include "system.h"
28 #define INIT_MAIN_THREAD
30 #define THREAD_STARTUP_INIT(core, thread, function) \
31 ({ (thread)->context.stack_size = (thread)->stack_size, \
32 (thread)->context.stack = (uintptr_t)(thread)->stack; \
33 (thread)->context.start = function; })
35 static void init_main_thread(void *addr)
37 struct regs *context = (struct regs*)addr;
38 /* we must convert the current main thread to a fiber to be able to
39 * schedule other fibers */
40 context->uc = ConvertThreadToFiber(NULL);
41 context->stack_size = 0;
44 static inline void store_context(void* addr)
46 (void)addr;
47 /* nothing to do here, Fibers continue after the SwitchToFiber call */
50 static void start_thread(void)
52 void (*func)(void) = GetFiberData();
53 func();
54 /* go out if thread function returns */
55 thread_exit();
59 * Load context and run it
61 * Resume execution from the last load_context call for the thread
64 static inline void load_context(const void* addr)
66 struct regs *context = (struct regs*)addr;
67 if (UNLIKELY(context->start))
68 { /* need setup before switching to it */
69 context->uc = CreateFiber(context->stack_size,
70 (LPFIBER_START_ROUTINE)start_thread, context->start);
71 /* can't assign stack pointer, only stack size */
72 context->stack_size = 0;
73 context->start = NULL;
75 SwitchToFiber(context->uc);