#include "SDL_atomic.h"
#include "SDL_cpuinfo.h"
#include "../thread/SDL_systhread.h"
-#include "xf86drm.h"
-#include <fcntl.h>
/* #define DEBUG_TIMERS */
-
typedef struct _SDL_Timer
{
int timerID;
/* List of timers - this is only touched by the timer thread */
SDL_Timer *timers;
-
- int drm_fd;
- drmVBlank vblankInfo;
} SDL_TimerData;
static SDL_TimerData SDL_timer_data;
* 3. Wait until next dispatch time or new timer arrives
*/
for ( ; ; ) {
-#if defined(__TIZEN__)
- if(data->drm_fd > -1) {
- if(!SDL_AtomicGet(&data->active))
- break;
- if(drmWaitVBlank(data->drm_fd, &(data->vblankInfo)) == 0) {
- if(data->pending) {
- current = data->pending;
- current->callback(current->interval, current->param);
- }
- }
- }
- else
-#endif
+ /* Pending and freelist maintenance */
+ SDL_AtomicLock(&data->lock);
{
- /* Pending and freelist maintenance */
- SDL_AtomicLock(&data->lock);
- {
- /* Get any timers ready to be queued */
- pending = data->pending;
- data->pending = NULL;
-
- /* Make any unused timer structures available */
- if (freelist_head) {
- freelist_tail->next = data->freelist;
- data->freelist = freelist_head;
- }
+ /* Get any timers ready to be queued */
+ pending = data->pending;
+ data->pending = NULL;
+
+ /* Make any unused timer structures available */
+ if (freelist_head) {
+ freelist_tail->next = data->freelist;
+ data->freelist = freelist_head;
}
- SDL_AtomicUnlock(&data->lock);
+ }
+ SDL_AtomicUnlock(&data->lock);
- /* Sort the pending timers into our list */
- while (pending) {
- current = pending;
- pending = pending->next;
- SDL_AddTimerInternal(data, current);
- }
- freelist_head = NULL;
- freelist_tail = NULL;
+ /* Sort the pending timers into our list */
+ while (pending) {
+ current = pending;
+ pending = pending->next;
+ SDL_AddTimerInternal(data, current);
+ }
+ freelist_head = NULL;
+ freelist_tail = NULL;
/* Check to see if we're still running, after maintenance */
if (!SDL_AtomicGet(&data->active)) {
+ break;
+ }
- /* Check to see if we're still running, after maintenance */
- break;
- }
-
- /* Initial delay if there are no timers */
- delay = SDL_MUTEX_MAXWAIT;
+ /* Initial delay if there are no timers */
+ delay = SDL_MUTEX_MAXWAIT;
- tick = SDL_GetTicks();
+ tick = SDL_GetTicks();
- /* Process all the pending timers for this tick */
- while (data->timers) {
- current = data->timers;
+ /* Process all the pending timers for this tick */
+ while (data->timers) {
+ current = data->timers;
- if ((Sint32)(tick-current->scheduled) < 0) {
- /* Scheduled for the future, wait a bit */
- delay = (current->scheduled - tick);
- break;
- }
+ if ((Sint32)(tick-current->scheduled) < 0) {
+ /* Scheduled for the future, wait a bit */
+ delay = (current->scheduled - tick);
+ break;
+ }
- /* We're going to do something with this timer */
- data->timers = current->next;
+ /* We're going to do something with this timer */
+ data->timers = current->next;
if (SDL_AtomicGet(¤t->canceled)) {
interval = 0;
if (interval > 0) {
/* Reschedule this timer */
current->interval = interval;
-
- /* Reschedule this timer */
- current->scheduled = tick + interval;
- SDL_AddTimerInternal(data, current);
- } else {
- if (!freelist_head) {
- freelist_head = current;
- }
- if (freelist_tail) {
- freelist_tail->next = current;
- }
- freelist_tail = current;
-
- SDL_AtomicSet(¤t->canceled, 1);
+ current->scheduled = tick + interval;
+ SDL_AddTimerInternal(data, current);
+ } else {
+ if (!freelist_head) {
+ freelist_head = current;
}
- }
+ if (freelist_tail) {
+ freelist_tail->next = current;
+ }
+ freelist_tail = current;
- /* Adjust the delay based on processing time */
- now = SDL_GetTicks();
- interval = (now - tick);
- if (interval > delay) {
- delay = 0;
- } else {
- delay -= interval;
+ SDL_AtomicSet(¤t->canceled, 1);
}
+ }
- /* Note that each time a timer is added, this will return
- immediately, but we process the timers added all at once.
- That's okay, it just means we run through the loop a few
- extra times.
- */
- SDL_SemWaitTimeout(data->sem, delay);
+ /* Adjust the delay based on processing time */
+ now = SDL_GetTicks();
+ interval = (now - tick);
+ if (interval > delay) {
+ delay = 0;
+ } else {
+ delay -= interval;
}
+
+ /* Note that each time a timer is added, this will return
+ immediately, but we process the timers added all at once.
+ That's okay, it just means we run through the loop a few
+ extra times.
+ */
+ SDL_SemWaitTimeout(data->sem, delay);
}
return 0;
}
SDL_AtomicSet(&data->active, 1);
-#if defined(__TIZEN__)
- const char* DRM_DEVICE = "/dev/dri/card0";
- data->drm_fd = -1;
- data->drm_fd = open( DRM_DEVICE, O_RDWR );
-
- if (data->drm_fd > -1) {
- data->vblankInfo.request.type = DRM_VBLANK_NEXTONMISS;
- data->vblankInfo.request.sequence = 0;
- data->vblankInfo.request.signal = 0;
-
- data->vblankInfo.reply.type = DRM_VBLANK_NEXTONMISS;
- data->vblankInfo.reply.sequence = 0;
- data->vblankInfo.reply.tval_sec = 0;
- data->vblankInfo.reply.tval_usec = 0;
- }
-#endif
- /* !!! FIXME: this is nasty. */
-
/* Timer threads use a callback into the app, so we can't set a limited stack size here. */
data->thread = SDL_CreateThreadInternal(SDL_TimerThread, name, 0, data);
if (!data->thread) {