From 60901771ead6fe48c4deefc42b711f61a0dd9d9f Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 23 Oct 2014 08:19:36 +0200 Subject: [PATCH] (Libretro SDK) Libco - style nits --- libretro-sdk/include/libco.h | 3 +++ libretro-sdk/libco/amd64.c | 3 ++- libretro-sdk/libco/armeabi.c | 27 ++++++++++++++------------- libretro-sdk/libco/sjlj.c | 13 ++++++++----- libretro-sdk/libco/x86.c | 3 ++- 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/libretro-sdk/include/libco.h b/libretro-sdk/include/libco.h index 9b180cb76a..1464804506 100644 --- a/libretro-sdk/include/libco.h +++ b/libretro-sdk/include/libco.h @@ -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 diff --git a/libretro-sdk/libco/amd64.c b/libretro-sdk/libco/amd64.c index 8cc0345946..87b3f8b2ed 100644 --- a/libretro-sdk/libco/amd64.c +++ b/libretro-sdk/libco/amd64.c @@ -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 diff --git a/libretro-sdk/libco/armeabi.c b/libretro-sdk/libco/armeabi.c index a7d4db17bc..9be768f61f 100644 --- a/libretro-sdk/libco/armeabi.c +++ b/libretro-sdk/libco/armeabi.c @@ -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; } diff --git a/libretro-sdk/libco/sjlj.c b/libretro-sdk/libco/sjlj.c index 028515bec6..f074714364 100644 --- a/libretro-sdk/libco/sjlj.c +++ b/libretro-sdk/libco/sjlj.c @@ -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; } diff --git a/libretro-sdk/libco/x86.c b/libretro-sdk/libco/x86.c index aed16cb603..693719fa16 100644 --- a/libretro-sdk/libco/x86.c +++ b/libretro-sdk/libco/x86.c @@ -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