mirror of
https://github.com/CTCaer/RetroArch.git
synced 2024-12-16 07:16:36 +00:00
(Libretro SDK) Libco - style nits
This commit is contained in:
parent
9354fd05b1
commit
60901771ea
@ -22,8 +22,11 @@ extern "C" {
|
||||
typedef void* cothread_t;
|
||||
|
||||
cothread_t co_active(void);
|
||||
|
||||
cothread_t co_create(unsigned int, void (*)(void));
|
||||
|
||||
void co_delete(cothread_t);
|
||||
|
||||
void co_switch(cothread_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -40,7 +40,8 @@ static unsigned char co_swap_function[] = {
|
||||
void co_init(void)
|
||||
{
|
||||
DWORD old_privileges;
|
||||
VirtualProtect(co_swap_function, sizeof(co_swap_function), PAGE_EXECUTE_READWRITE, &old_privileges);
|
||||
VirtualProtect(co_swap_function,
|
||||
sizeof(co_swap_function), PAGE_EXECUTE_READWRITE, &old_privileges);
|
||||
}
|
||||
#else
|
||||
//ABI: SystemV
|
||||
|
@ -29,12 +29,13 @@ asm (
|
||||
" ldmia r0!, {r4, r5, r6, r7, r8, r9, r10, r11, sp, pc}\n"
|
||||
);
|
||||
|
||||
// ASM
|
||||
/* ASM */
|
||||
void co_switch_arm(cothread_t handle, cothread_t current);
|
||||
|
||||
static void crash(void)
|
||||
{
|
||||
assert(0); // Called only if cothread_t entrypoint returns.
|
||||
/* Called only if cothread_t entrypoint returns. */
|
||||
assert(0);
|
||||
}
|
||||
|
||||
cothread_t co_create(unsigned int size, void (*entrypoint)(void))
|
||||
@ -52,17 +53,17 @@ cothread_t co_create(unsigned int size, void (*entrypoint)(void))
|
||||
return handle;
|
||||
|
||||
uint32_t *ptr = (uint32_t*)handle;
|
||||
// Non-volatiles
|
||||
ptr[0] = 0; // r4
|
||||
ptr[1] = 0; // r5
|
||||
ptr[2] = 0; // r6
|
||||
ptr[3] = 0; // r7
|
||||
ptr[4] = 0; // r8
|
||||
ptr[5] = 0; // r9
|
||||
ptr[6] = 0; // r10
|
||||
ptr[7] = 0; // r11
|
||||
ptr[8] = (uintptr_t)ptr + size + 256 - 4; // r13, stack pointer
|
||||
ptr[9] = (uintptr_t)entrypoint; // r15, PC (link register r14 gets saved here).
|
||||
/* Non-volatiles. */
|
||||
ptr[0] = 0; /* r4 */
|
||||
ptr[1] = 0; /* r5 */
|
||||
ptr[2] = 0; /* r6 */
|
||||
ptr[3] = 0; /* r7 */
|
||||
ptr[4] = 0; /* r8 */
|
||||
ptr[5] = 0; /* r9 */
|
||||
ptr[6] = 0; /* r10 */
|
||||
ptr[7] = 0; /* r11 */
|
||||
ptr[8] = (uintptr_t)ptr + size + 256 - 4; /* r13, stack pointer */
|
||||
ptr[9] = (uintptr_t)entrypoint; /* r15, PC (link register r14 gets saved here). */
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
@ -64,22 +64,25 @@ cothread_t co_create(unsigned int size, void (*coentry)(void))
|
||||
stack.ss_flags = 0;
|
||||
stack.ss_size = size;
|
||||
thread->stack = stack.ss_sp = malloc(size);
|
||||
if(stack.ss_sp && !sigaltstack(&stack, &old_stack)) {
|
||||
|
||||
if(stack.ss_sp && !sigaltstack(&stack, &old_stack))
|
||||
{
|
||||
handler.sa_handler = springboard;
|
||||
handler.sa_flags = SA_ONSTACK;
|
||||
sigemptyset(&handler.sa_mask);
|
||||
creating = thread;
|
||||
|
||||
if(!sigaction(SIGUSR1, &handler, &old_handler)) {
|
||||
if(!raise(SIGUSR1)) {
|
||||
if(!sigaction(SIGUSR1, &handler, &old_handler))
|
||||
{
|
||||
if(!raise(SIGUSR1))
|
||||
thread->coentry = coentry;
|
||||
}
|
||||
sigaltstack(&old_stack, 0);
|
||||
sigaction(SIGUSR1, &old_handler, 0);
|
||||
}
|
||||
}
|
||||
|
||||
if(thread->coentry != coentry) {
|
||||
if(thread->coentry != coentry)
|
||||
{
|
||||
co_delete(thread);
|
||||
thread = 0;
|
||||
}
|
||||
|
@ -37,7 +37,8 @@ static unsigned char co_swap_function[] = {
|
||||
void co_init(void)
|
||||
{
|
||||
DWORD old_privileges;
|
||||
VirtualProtect(co_swap_function, sizeof co_swap_function, PAGE_EXECUTE_READWRITE, &old_privileges);
|
||||
VirtualProtect(co_swap_function,
|
||||
sizeof co_swap_function, PAGE_EXECUTE_READWRITE, &old_privileges);
|
||||
}
|
||||
#else
|
||||
#include <unistd.h>
|
||||
|
Loading…
Reference in New Issue
Block a user