Example #1
0
int SDL_SetTimer(Uint32 ms, SDL_TimerCallback callback)
{
	int retval;

#ifdef DEBUG_TIMERS
	printf("SDL_SetTimer(%d)\n", ms);
#endif
	retval = 0;
	if ( SDL_timer_running ) {	/* Stop any currently running timer */
		SDL_timer_running = 0;
		if ( SDL_timer_threaded ) {
			SDL_mutexP(SDL_timer_mutex);
			SDL_RemoveAllTimers(SDL_timers);
			SDL_timers = NULL;
			SDL_mutexV(SDL_timer_mutex);
		} else {
			SDL_SYS_StopTimer();
		}
	}
	if ( ms ) {
		if ( SDL_timer_threaded ) {
			retval = (SDL_AddTimer(ms, callback_wrapper,
					       (void *)callback) != NULL);
		} else {
			SDL_timer_running = 1;
			SDL_alarm_interval = ms;
			SDL_alarm_callback = callback;
			retval = SDL_SYS_StartTimer();
		}
	}
	return retval;
}
Example #2
0
int
SDL_SetTimer(Uint32 ms, SDL_TimerCallback callback)
{
    int retval;

#ifdef DEBUG_TIMERS
    printf("SDL_SetTimer(%d)\n", ms);
#endif
    retval = 0;

    if (SDL_timer_threaded) {
        SDL_mutexP(SDL_timer_mutex);
    }
    if (SDL_timer_running) {    /* Stop any currently running timer */
        if (SDL_timer_threaded) {
            while (SDL_timers) {
                SDL_TimerID freeme = SDL_timers;
                SDL_timers = SDL_timers->next;
                SDL_free(freeme);
            }
            SDL_timer_running = 0;
            list_changed = SDL_TRUE;
        } else {
            SDL_SYS_StopTimer();
            SDL_timer_running = 0;
        }
    }
    if (ms) {
        if (SDL_timer_threaded) {
            if (SDL_AddTimerInternal
                (ms, callback_wrapper, (void *) callback) == NULL) {
                retval = -1;
            }
        } else {
            SDL_timer_running = 1;
            SDL_alarm_interval = ms;
            SDL_alarm_callback = callback;
            retval = SDL_SYS_StartTimer();
        }
    }
    if (SDL_timer_threaded) {
        SDL_mutexV(SDL_timer_mutex);
    }

    return retval;
}