diff options
Diffstat (limited to 'src/osd/modules/lib')
-rw-r--r-- | src/osd/modules/lib/osdlib_macosx.cpp | 146 | ||||
-rw-r--r-- | src/osd/modules/lib/osdlib_unix.cpp | 67 | ||||
-rw-r--r-- | src/osd/modules/lib/osdlib_win32.cpp | 106 |
3 files changed, 1 insertions, 318 deletions
diff --git a/src/osd/modules/lib/osdlib_macosx.cpp b/src/osd/modules/lib/osdlib_macosx.cpp index 0d89e6c3596..501719c1e3c 100644 --- a/src/osd/modules/lib/osdlib_macosx.cpp +++ b/src/osd/modules/lib/osdlib_macosx.cpp @@ -14,11 +14,6 @@ #include <sys/types.h> #include <signal.h> -#include <mach/mach.h> -#include <mach/mach_time.h> -#include <mach/mach_traps.h> -#include <Carbon/Carbon.h> - // MAME headers #include "osdcore.h" #include "osdlib.h" @@ -55,30 +50,6 @@ void osd_process_kill(void) } //============================================================ -// osd_num_processors -//============================================================ - -int osd_get_num_processors(void) -{ - int processors = 1; - - struct host_basic_info host_basic_info; - unsigned int count; - kern_return_t r; - mach_port_t my_mach_host_self; - - count = HOST_BASIC_INFO_COUNT; - my_mach_host_self = mach_host_self(); - if ( ( r = host_info(my_mach_host_self, HOST_BASIC_INFO, (host_info_t)(&host_basic_info), &count)) == KERN_SUCCESS ) - { - processors = host_basic_info.avail_cpus; - } - mach_port_deallocate(mach_task_self(), my_mach_host_self); - - return processors; -} - -//============================================================ // osd_malloc //============================================================ @@ -166,120 +137,3 @@ void osd_break_into_debugger(const char *message) #endif } - -//============================================================ -// PROTOTYPES -//============================================================ - -static osd_ticks_t init_cycle_counter(void); -static osd_ticks_t mach_cycle_counter(void); - -//============================================================ -// STATIC VARIABLES -//============================================================ - -static osd_ticks_t (*cycle_counter)(void) = init_cycle_counter; -static osd_ticks_t (*ticks_counter)(void) = init_cycle_counter; -static osd_ticks_t ticks_per_second; - -//============================================================ -// init_cycle_counter -// -// to avoid total grossness, this function is split by subarch -//============================================================ - -static osd_ticks_t init_cycle_counter(void) -{ - osd_ticks_t start, end; - osd_ticks_t a, b; - - cycle_counter = mach_cycle_counter; - ticks_counter = mach_cycle_counter; - - // wait for an edge on the timeGetTime call - a = SDL_GetTicks(); - do - { - b = SDL_GetTicks(); - } while (a == b); - - // get the starting cycle count - start = (*cycle_counter)(); - - // now wait for 1/4 second total - do - { - a = SDL_GetTicks(); - } while (a - b < 250); - - // get the ending cycle count - end = (*cycle_counter)(); - - // compute ticks_per_sec - ticks_per_second = (end - start) * 4; - - // return the current cycle count - return (*cycle_counter)(); -} - -//============================================================ -// performance_cycle_counter -//============================================================ - -//============================================================ -// mach_cycle_counter -//============================================================ -static osd_ticks_t mach_cycle_counter(void) -{ - return mach_absolute_time(); -} - -//============================================================ -// osd_ticks -//============================================================ - -osd_ticks_t osd_ticks(void) -{ - return (*cycle_counter)(); -} - - -//============================================================ -// osd_ticks_per_second -//============================================================ - -osd_ticks_t osd_ticks_per_second(void) -{ - if (ticks_per_second == 0) - { - // if we haven't computed the value yet, there's no time like the present - init_cycle_counter(); - } - return ticks_per_second; -} - - - -//============================================================ -// osd_sleep -//============================================================ - -void osd_sleep(osd_ticks_t duration) -{ - UINT32 msec; - - // make sure we've computed ticks_per_second - if (ticks_per_second == 0) - (void)osd_ticks(); - - // convert to milliseconds, rounding down - msec = (UINT32)(duration * 1000 / ticks_per_second); - - // only sleep if at least 2 full milliseconds - if (msec >= 2) - { - // take a couple of msecs off the top for good measure - msec -= 2; - usleep(msec*1000); - } -} diff --git a/src/osd/modules/lib/osdlib_unix.cpp b/src/osd/modules/lib/osdlib_unix.cpp index a275eb04192..3075ea63769 100644 --- a/src/osd/modules/lib/osdlib_unix.cpp +++ b/src/osd/modules/lib/osdlib_unix.cpp @@ -13,8 +13,7 @@ #include <sys/mman.h> #include <sys/types.h> #include <signal.h> -#include <time.h> -#include <sys/time.h> + #ifdef SDLMAME_EMSCRIPTEN #include <emscripten.h> #endif @@ -51,20 +50,6 @@ void osd_process_kill(void) } //============================================================ -// osd_num_processors -//============================================================ - -int osd_get_num_processors(void) -{ - int processors = 1; - -#if defined(_SC_NPROCESSORS_ONLN) - processors = sysconf(_SC_NPROCESSORS_ONLN); -#endif - return processors; -} - -//============================================================ // osd_malloc //============================================================ @@ -150,53 +135,3 @@ void osd_break_into_debugger(const char *message) printf("Ignoring MAME exception: %s\n", message); #endif } - - -//============================================================ -// osd_ticks -//============================================================ - -osd_ticks_t osd_ticks(void) -{ -#ifdef SDLMAME_EMSCRIPTEN - return (osd_ticks_t)(emscripten_get_now() * 1000.0); -#else - struct timeval tp; - static osd_ticks_t start_sec = 0; - - gettimeofday(&tp, NULL); - if (start_sec==0) - start_sec = tp.tv_sec; - return (tp.tv_sec - start_sec) * (osd_ticks_t) 1000000 + tp.tv_usec; -#endif -} - - -//============================================================ -// osd_ticks_per_second -//============================================================ - -osd_ticks_t osd_ticks_per_second(void) -{ - return (osd_ticks_t) 1000000; -} - -//============================================================ -// osd_sleep -//============================================================ - -void osd_sleep(osd_ticks_t duration) -{ - UINT32 msec; - - // convert to milliseconds, rounding down - msec = (UINT32)(duration * 1000 / osd_ticks_per_second()); - - // only sleep if at least 2 full milliseconds - if (msec >= 2) - { - // take a couple of msecs off the top for good measure - msec -= 2; - usleep(msec*1000); - } -} diff --git a/src/osd/modules/lib/osdlib_win32.cpp b/src/osd/modules/lib/osdlib_win32.cpp index 75218574aff..bb6f136be90 100644 --- a/src/osd/modules/lib/osdlib_win32.cpp +++ b/src/osd/modules/lib/osdlib_win32.cpp @@ -101,21 +101,6 @@ void osd_process_kill(void) } //============================================================ -// osd_num_processors -//============================================================ - -int osd_get_num_processors(void) -{ - SYSTEM_INFO info; - - // otherwise, fetch the info from the system - GetSystemInfo(&info); - - // max out at 4 for now since scaling above that seems to do poorly - return MIN(info.dwNumberOfProcessors, 4); -} - -//============================================================ // osd_malloc //============================================================ @@ -256,94 +241,3 @@ void osd_break_into_debugger(const char *message) #endif } -//============================================================ -// GLOBAL VARIABLES -//============================================================ - -static osd_ticks_t ticks_per_second = 0; -static osd_ticks_t suspend_ticks = 0; -static BOOL using_qpc = TRUE; - - - -//============================================================ -// osd_ticks -//============================================================ - -osd_ticks_t osd_ticks(void) -{ - LARGE_INTEGER performance_count; - - // if we're suspended, just return that - if (suspend_ticks != 0) - return suspend_ticks; - - // if we have a per second count, just go for it - if (ticks_per_second != 0) - { - // QueryPerformanceCounter if we can - if (using_qpc) - { - QueryPerformanceCounter(&performance_count); - return (osd_ticks_t)performance_count.QuadPart - suspend_ticks; - } - - // otherwise, fall back to timeGetTime - else - return (osd_ticks_t)timeGetTime() - suspend_ticks; - } - - // if not, we have to determine it - using_qpc = QueryPerformanceFrequency(&performance_count) && (performance_count.QuadPart != 0); - if (using_qpc) - ticks_per_second = (osd_ticks_t)performance_count.QuadPart; - else - ticks_per_second = 1000; - - // call ourselves to get the first value - return osd_ticks(); -} - - -//============================================================ -// osd_ticks_per_second -//============================================================ - -osd_ticks_t osd_ticks_per_second(void) -{ - if (ticks_per_second == 0) - osd_ticks(); - return ticks_per_second; -} - -//============================================================ -// osd_sleep -//============================================================ - -void osd_sleep(osd_ticks_t duration) -{ - DWORD msec; - - // make sure we've computed ticks_per_second - if (ticks_per_second == 0) - (void)osd_ticks(); - - // convert to milliseconds, rounding down - msec = (DWORD)(duration * 1000 / ticks_per_second); - - // only sleep if at least 2 full milliseconds - if (msec >= 2) - { - HANDLE current_thread = GetCurrentThread(); - int old_priority = GetThreadPriority(current_thread); - - // take a couple of msecs off the top for good measure - msec -= 2; - - // bump our thread priority super high so that we get - // priority when we need it - SetThreadPriority(current_thread, THREAD_PRIORITY_TIME_CRITICAL); - Sleep(msec); - SetThreadPriority(current_thread, old_priority); - } -} |