/* psp_timer_thread: * This PSP thread measures the elapsed time. */ static int psp_timer_thread() { uint64_t old_tick, new_tick; int interval; long delay; sceRtcGetCurrentTick(&old_tick); while (psp_timer_on) { /* Calculate actual time elapsed. */ sceRtcGetCurrentTick(&new_tick); interval = PSPTIMER_TO_TIMER(new_tick - old_tick); old_tick = new_tick; /* Handle a tick and rest. */ delay = _handle_timer_tick(interval); sceKernelDelayThreadCB(TIMER_TO_USEC(delay)); } sceKernelExitThread(0); return 0; }
/* ptimer_thread_func: * The timer thread. */ static void *ptimer_thread_func(void *unused) { struct timeval old_time; struct timeval new_time; struct timeval delay; long interval = 0x8000; #ifdef ALLEGRO_HAVE_POSIX_MONOTONIC_CLOCK struct timespec old_time_ns; struct timespec new_time_ns; int clock_monotonic; #endif block_all_signals(); #ifdef ALLEGRO_LINUX_VGA /* privileges hack for Linux: * One of the jobs of the timer thread is to update the mouse pointer * on screen. When using the Mode-X driver under Linux console, this * involves selecting different planes (in modexgfx.s), which requires * special priviledges. */ if ((system_driver == &system_linux) && (__al_linux_have_ioperms)) { seteuid(0); iopl(3); seteuid(getuid()); } #endif #ifdef ALLEGRO_QNX /* thread priority adjustment for QNX: * The timer thread is set to the highest relative priority. * (see the comment in src/qnx/qsystem.c about the scheduling policy) */ { struct sched_param sparam; int spolicy; if (pthread_getschedparam(pthread_self(), &spolicy, &sparam) == EOK) { sparam.sched_priority += 4; pthread_setschedparam(pthread_self(), spolicy, &sparam); } } #endif #ifdef ALLEGRO_HAVE_POSIX_MONOTONIC_CLOCK /* clock_gettime(CLOCK_MONOTONIC, ...) is preferable to gettimeofday() in * case the system time is changed while the program is running. * CLOCK_MONOTONIC is not available on all systems. */ clock_monotonic = (clock_gettime(CLOCK_MONOTONIC, &old_time_ns) == 0); #endif gettimeofday(&old_time, 0); while (thread_alive) { /* `select' is more accurate than `usleep' on my system. */ delay.tv_sec = interval / TIMERS_PER_SECOND; delay.tv_usec = TIMER_TO_USEC(interval) % 1000000L; select(0, NULL, NULL, NULL, &delay); /* Calculate actual time elapsed. */ #ifdef ALLEGRO_HAVE_POSIX_MONOTONIC_CLOCK if (clock_monotonic) { clock_gettime(CLOCK_MONOTONIC, &new_time_ns); interval = USEC_TO_TIMER( (new_time_ns.tv_sec - old_time_ns.tv_sec) * 1000000L + (new_time_ns.tv_nsec - old_time_ns.tv_nsec) / 1000); old_time_ns = new_time_ns; } else #endif { gettimeofday(&new_time, 0); interval = USEC_TO_TIMER( (new_time.tv_sec - old_time.tv_sec) * 1000000L + (new_time.tv_usec - old_time.tv_usec)); old_time = new_time; } /* Handle a tick. */ interval = _handle_timer_tick(interval); } return NULL; }