diff --git a/libretro-common/features/features_cpu.c b/libretro-common/features/features_cpu.c index 7d1d98cfdc..63d01427a4 100644 --- a/libretro-common/features/features_cpu.c +++ b/libretro-common/features/features_cpu.c @@ -189,22 +189,18 @@ retro_perf_tick_t cpu_features_get_perf_counter(void) time_ticks = __mftb(); #elif defined(GEKKO) time_ticks = gettime(); -#elif defined(PSP) - sceRtcGetCurrentTick((uint64_t*)&time_ticks); -#elif defined(VITA) - sceRtcGetCurrentTick((SceRtcTick*)&time_ticks); +#elif defined(PSP) || defined(VITA) + time_ticks = sceKernelGetSystemTimeWide(); #elif defined(PS2) time_ticks = clock()*294912; // 294,912MHZ / 1000 msecs #elif defined(_3DS) time_ticks = svcGetSystemTick(); #elif defined(WIIU) time_ticks = OSGetSystemTime(); -#elif defined(__mips__) - struct timeval tv; - gettimeofday(&tv,NULL); - time_ticks = (1000000 * tv.tv_sec + tv.tv_usec); #elif defined(HAVE_LIBNX) time_ticks = armGetSystemTick(); +#elif defined(EMSCRIPTEN) + time_ticks = emscripten_get_now() * 1000; #endif return time_ticks; @@ -248,11 +244,11 @@ retro_time_t cpu_features_get_time_usec(void) #elif defined(EMSCRIPTEN) return emscripten_get_now() * 1000; #elif defined(PS2) - return clock()*(1000000LL/CLOCKS_PER_SEC); -#elif defined(_3DS) - return osGetTime() * 1000; + return clock()*1000; #elif defined(VITA) || defined(PSP) return sceKernelGetSystemTimeWide(); +#elif defined(_3DS) + return osGetTime() * 1000; #else #error "Your platform does not have a timer function implemented in cpu_features_get_time_usec(). Cannot continue." #endif diff --git a/libretro-common/libco/armeabi.c b/libretro-common/libco/armeabi.c index f03a356794..3f0ea1a30c 100644 --- a/libretro-common/libco/armeabi.c +++ b/libretro-common/libco/armeabi.c @@ -24,10 +24,13 @@ static thread_local cothread_t co_active_handle; __asm__ ( #if defined(__thumb2__) - ".thumb\n" ".align 2\n" ".globl co_switch_arm\n" ".globl _co_switch_arm\n" + ".thumb\n" + ".thumb_func\n" + ".type co_switch_arm, %function\n" + ".type _co_switch_arm, %function\n" "co_switch_arm:\n" "_co_switch_arm:\n" " mov r3, sp\n" diff --git a/libretro-common/libco/psp1.c b/libretro-common/libco/psp1.c index 45850a4d83..75a71c22e7 100644 --- a/libretro-common/libco/psp1.c +++ b/libretro-common/libco/psp1.c @@ -4,42 +4,38 @@ #include #include -/* Since cothread_t is a void pointer it must contain an address. We can't return a reference to a local variable - * because it would go out of scope, so we create a static variable instead so we can return a reference to it. - */ -static SceUID active_thread_id = 0; +typedef void (*entrypoint_t)(void); cothread_t co_active() { - active_thread_id = sceKernelGetThreadId(); - return &active_thread_id; + return (void *) sceKernelGetThreadId(); +} + +static int thread_wrap(unsigned int argc, void *argp) +{ + entrypoint_t entrypoint = *(entrypoint_t *) argp; + sceKernelSleepThread(); + entrypoint(); + return 0; } cothread_t co_create(unsigned int size, void (*entrypoint)(void)) { - /* Similar scenario as with active_thread_id except there will only be one active_thread_id while there could be many - * new threads each with their own handle, so we create them on the heap instead and delete them manually when they're - * no longer needed in co_delete(). - */ - cothread_t handle = malloc(sizeof(cothread_t)); - - /* SceKernelThreadEntry has a different signature than entrypoint, but in practice this seems to work */ - SceUID new_thread_id = sceKernelCreateThread("cothread", (SceKernelThreadEntry)entrypoint, 0x12, size, 0, NULL); - sceKernelStartThread(new_thread_id, 0, NULL); - - *(SceUID *)handle = new_thread_id; - return handle; + SceUID new_thread_id = sceKernelCreateThread("cothread", thread_wrap, 0x12, size, 0, NULL); + sceKernelStartThread(new_thread_id, sizeof (entrypoint), &entrypoint); + return (void *) new_thread_id; } void co_delete(cothread_t handle) { - sceKernelTerminateDeleteThread(*(SceUID *)handle); - free(handle); + SceUID id = (SceUID) handle; + sceKernelTerminateDeleteThread(id); } void co_switch(cothread_t handle) { - sceKernelWakeupThread(*(SceUID *)handle); + SceUID id = (SceUID) handle; + sceKernelWakeupThread(id); /* Sleep the currently active thread so the new thread can start */ sceKernelSleepThread(); -} \ No newline at end of file +} diff --git a/libretro-common/streams/file_stream.c b/libretro-common/streams/file_stream.c index bacd810943..b8d4c49ece 100644 --- a/libretro-common/streams/file_stream.c +++ b/libretro-common/streams/file_stream.c @@ -275,11 +275,17 @@ int filestream_scanf(RFILE *stream, const char* format, ...) if (sizeof(void*) != sizeof(long*)) abort(); /* all pointers must have the same size */ if (asterisk) { - if (sscanf(bufiter, subfmt, &sublen) != 0) break; + int v = sscanf(bufiter, subfmt, &sublen); + if (v == EOF) + return EOF; + if (v != 0) break; } else { - if (sscanf(bufiter, subfmt, va_arg(args, void*), &sublen) != 1) break; + int v = sscanf(bufiter, subfmt, va_arg(args, void*), &sublen); + if (v == EOF) + return EOF; + if (v != 1) break; } ret++;