Revert Tizen timer 29/290829/1 accepted/tizen/8.0/unified/20231005.094602 accepted/tizen/unified/20230407.140017
authorDaekwang Ryu <dkdk.ryu@samsung.com>
Tue, 4 Apr 2023 02:26:56 +0000 (11:26 +0900)
committerDaekwang Ryu <dkdk.ryu@samsung.com>
Tue, 4 Apr 2023 04:15:04 +0000 (13:15 +0900)
This file was changed to the upstream SDL file as v2.0.14.

Change-Id: I57c5de8b0096f3c06fbf3ef2d8f2d624405b9870

src/timer/SDL_timer.c

index c1cd86d..4e8ea01 100644 (file)
 #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;
@@ -69,9 +66,6 @@ typedef struct {
 
     /* 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;
@@ -119,68 +113,52 @@ SDL_TimerThread(void *_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(&current->canceled)) {
                 interval = 0;
@@ -191,39 +169,36 @@ SDL_TimerThread(void *_data)
             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(&current->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(&current->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;
 }
@@ -248,24 +223,6 @@ SDL_TimerInit(void)
 
         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) {