A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 76 lines 2.4 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2010 by Thomas Martitz 11 * 12 * Generic ARM threading support 13 * 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. 18 * 19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 20 * KIND, either express or implied. 21 * 22 ****************************************************************************/ 23 24 25#include <windows.h> 26#include "system.h" 27 28#define INIT_MAIN_THREAD 29 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; }) 34 35static void init_main_thread(void *addr) 36{ 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; 42} 43 44static inline void store_context(void* addr) 45{ 46 (void)addr; 47 /* nothing to do here, Fibers continue after the SwitchToFiber call */ 48} 49 50static void start_thread(void) 51{ 52 void (*func)(void) = GetFiberData(); 53 func(); 54 /* go out if thread function returns */ 55 thread_exit(); 56} 57 58/* 59 * Load context and run it 60 * 61 * Resume execution from the last load_context call for the thread 62 */ 63 64static inline void load_context(const void* addr) 65{ 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; 74 } 75 SwitchToFiber(context->uc); 76}