Exemplo n.º 1
0
/* This is only called if the event thread is not running */
int SDL_SYS_TimerInit(void)
{
	timer_alive = 1;
	timer = SDL_CreateThread(RunTimer, NULL);
	if ( timer == NULL )
		return(-1);
	return(SDL_SetTimerThreaded(1));
}
Exemplo n.º 2
0
static int SDLCALL SDL_GobbleEvents(void *unused)
{
	event_thread = SDL_ThreadID();

#ifdef __OS2__
#ifdef USE_DOSSETPRIORITY
	/* Increase thread priority, so it will process events in time for sure! */
	DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, +16, 0);
#endif
#endif

	while ( SDL_EventQ.active ) {
		SDL_VideoDevice *video = current_video;
		SDL_VideoDevice *this  = current_video;

		/* Get events from the video subsystem */
		if ( video ) {
			video->PumpEvents(this);
		}

		/* Queue pending key-repeat events */
		SDL_CheckKeyRepeat();

#if !SDL_JOYSTICK_DISABLED
		/* Check for joystick state change */
		if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) {
			SDL_JoystickUpdate();
		}
#endif

		/* Give up the CPU for the rest of our timeslice */
		SDL_EventLock.safe = 1;
		if ( SDL_timer_running ) {
			SDL_ThreadedTimerCheck();
		}
		SDL_Delay(1);

		/* Check for event locking.
		   On the P of the lock mutex, if the lock is held, this thread
		   will wait until the lock is released before continuing.  The
		   safe flag will be set, meaning that the other thread can go
		   about it's business.  The safe flag is reset before the V,
		   so as soon as the mutex is free, other threads can see that
		   it's not safe to interfere with the event thread.
		 */
		SDL_mutexP(SDL_EventLock.lock);
		SDL_EventLock.safe = 0;
		SDL_mutexV(SDL_EventLock.lock);
	}
	SDL_SetTimerThreaded(0);
	event_thread = 0;
	return(0);
}
Exemplo n.º 3
0
/* This is only called if the event thread is not running */
int SDL_SYS_TimerInit(void)
{
	void *oldpile;

	supervisor=SDL_FALSE;

	/* Install RunTimer in vbl vector */
	oldpile=(void *)Super(0);
	timer_installed = !SDL_AtariVblInstall(RunTimer);
	Super(oldpile);

	if (!timer_installed) {
		return(-1);
	}
	return(SDL_SetTimerThreaded(0));
}
Exemplo n.º 4
0
static int SDLCALL SDL_GobbleEvents(void *unused)
{
	event_thread = SDL_ThreadID();

#ifdef __OS2__
#ifdef USE_DOSSETPRIORITY
	
	DosSetPriority(PRTYS_THREAD, PRTYC_REGULAR, +16, 0);
#endif
#endif

	while ( SDL_EventQ.active ) {
		SDL_VideoDevice *video = current_video;
		SDL_VideoDevice *this  = current_video;

		
		if ( video ) {
			video->PumpEvents(this);
		}

		
		SDL_CheckKeyRepeat();

#if !SDL_JOYSTICK_DISABLED
		
		if ( SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK) ) {
			SDL_JoystickUpdate();
		}
#endif

		
		SDL_EventLock.safe = 1;
		if ( SDL_timer_running ) {
			SDL_ThreadedTimerCheck();
		}
		SDL_Delay(1);

		SDL_mutexP(SDL_EventLock.lock);
		SDL_EventLock.safe = 0;
		SDL_mutexV(SDL_EventLock.lock);
	}
	SDL_SetTimerThreaded(0);
	event_thread = 0;
	return(0);
}
Exemplo n.º 5
0
/* This is only called if the event thread is not running */
int SDL_SYS_TimerInit(void)
{
	void *old_stack;

	SDL_MintAudio_CheckFpu();

	/* Install RunTimer in vbl vector */
	old_stack = (void *)Super(0);
	timer_installed = !SDL_AtariVblInstall(SDL_ThreadedTimerCheck);
	Super(old_stack);

	if (!timer_installed) {
		return(-1);
	}

	read_hz200_from_vbl = SDL_TRUE;
	return(SDL_SetTimerThreaded(0));
}
Exemplo n.º 6
0
int SDL_SYS_TimerInit(void)
{
	MMRESULT result;

	/* Set timer resolution */
	result = timeBeginPeriod(TIMER_RESOLUTION);
	if ( result != TIMERR_NOERROR ) {
		SDL_SetError("Warning: Can't set %d ms timer resolution",
							TIMER_RESOLUTION);
	}
	/* Allow 10 ms of drift so we don't chew on CPU */
	timerID = timeSetEvent(TIMER_RESOLUTION,1,HandleAlarm,0,TIME_PERIODIC);
	if ( ! timerID ) {
		SDL_SetError("timeSetEvent() failed");
		return(-1);
	}
	return(SDL_SetTimerThreaded(1));
}
Exemplo n.º 7
0
static int SDLCALL
SDL_GobbleEvents(void *unused)
{
    event_thread = SDL_ThreadID();

    while (SDL_EventQ.active) {
        SDL_VideoDevice *_this = SDL_GetVideoDevice();

        /* Get events from the video subsystem */
        if (_this) {
            _this->PumpEvents(_this);
        }
#if !SDL_JOYSTICK_DISABLED
        /* Check for joystick state change */
        if (SDL_numjoysticks && (SDL_eventstate & SDL_JOYEVENTMASK)) {
            SDL_JoystickUpdate();
        }
#endif

        /* Give up the CPU for the rest of our timeslice */
        SDL_EventLock.safe = 1;
        if (SDL_timer_running) {
            SDL_ThreadedTimerCheck();
        }
        SDL_Delay(1);

        /* Check for event locking.
           On the P of the lock mutex, if the lock is held, this thread
           will wait until the lock is released before continuing.  The
           safe flag will be set, meaning that the other thread can go
           about it's business.  The safe flag is reset before the V,
           so as soon as the mutex is free, other threads can see that
           it's not safe to interfere with the event thread.
         */
        SDL_mutexP(SDL_EventLock.lock);
        SDL_EventLock.safe = 0;
        SDL_mutexV(SDL_EventLock.lock);
    }
    SDL_SetTimerThreaded(0);
    event_thread = 0;
    return (0);
}
Exemplo n.º 8
0
static int SDL_StartEventThread(Uint32 flags)
{
	
	SDL_EventThread = NULL;
	SDL_memset(&SDL_EventLock, 0, sizeof(SDL_EventLock));

	
#if !SDL_THREADS_DISABLED
	SDL_EventQ.lock = SDL_CreateMutex();
	if ( SDL_EventQ.lock == NULL ) {
#ifdef __MACOS__ 
		;
#else
		return(-1);
#endif
	}
#endif 
	SDL_EventQ.active = 1;

	if ( (flags&SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD ) {
		SDL_EventLock.lock = SDL_CreateMutex();
		if ( SDL_EventLock.lock == NULL ) {
			return(-1);
		}
		SDL_EventLock.safe = 0;

		
		SDL_SetTimerThreaded(2);
#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) && !defined(__SYMBIAN32__)
#undef SDL_CreateThread
		SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL);
#else
		SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL);
#endif
		if ( SDL_EventThread == NULL ) {
			return(-1);
		}
	} else {
		event_thread = 0;
	}
	return(0);
}
Exemplo n.º 9
0
static int SDL_StartEventThread(Uint32 flags)
{
	/* Reset everything to zero */
	SDL_EventThread = NULL;
	SDL_memset(&SDL_EventLock, 0, sizeof(SDL_EventLock));

	/* Create the lock and set ourselves active */
#if !SDL_THREADS_DISABLED
	SDL_EventQ.lock = SDL_CreateMutex();
	if ( SDL_EventQ.lock == NULL ) {
#ifdef __MACOS__ /* MacOS classic you can't multithread, so no lock needed */
		;
#else
		return(-1);
#endif
	}
#endif /* !SDL_THREADS_DISABLED */
	SDL_EventQ.active = 1;

	if ( (flags&SDL_INIT_EVENTTHREAD) == SDL_INIT_EVENTTHREAD ) {
		SDL_EventLock.lock = SDL_CreateMutex();
		if ( SDL_EventLock.lock == NULL ) {
			return(-1);
		}
		SDL_EventLock.safe = 0;

		/* The event thread will handle timers too */
		SDL_SetTimerThreaded(2);
#if (defined(__WIN32__) && !defined(_WIN32_WCE)) && !defined(HAVE_LIBC) && !defined(__SYMBIAN32__)
#undef SDL_CreateThread
		SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL, NULL, NULL);
#else
		SDL_EventThread = SDL_CreateThread(SDL_GobbleEvents, NULL);
#endif
		if ( SDL_EventThread == NULL ) {
			return(-1);
		}
	} else {
		event_thread = 0;
	}
	return(0);
}
Exemplo n.º 10
0
int SDL_SYS_TimerInit(void)
{
	// create a thread to process a threaded timers
	// SetTimer does not suit the needs because 
	// TimerCallbackProc will be called only when WM_TIMER occured

	timersQuitEvent = CreateEvent(0, TRUE, FALSE, 0);
	if( !timersQuitEvent )
	{
		SDL_SetError("Cannot create event for timers thread");
		return -1;
	}
	timersThread = CreateThread(NULL, 0, TimersThreadProc, 0, 0, 0);
	if( !timersThread )
	{
		SDL_SetError("Cannot create timers thread, check amount of RAM available");
		return -1;
	}
	SetThreadPriority(timersThread, THREAD_PRIORITY_HIGHEST);

	return(SDL_SetTimerThreaded(1));
}