SDL: Updated SDL_TimerID to use the same type as other IDs in SDL

From d6a41f8f31172937ccfc81d082161a9eb148d30c Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 18 Jan 2024 05:07:28 -0800
Subject: [PATCH] Updated SDL_TimerID to use the same type as other IDs in SDL

---
 include/SDL3/SDL_timer.h    |  2 +-
 src/timer/SDL_timer.c       | 14 +++++---------
 test/testautomation_timer.c |  4 ++--
 3 files changed, 8 insertions(+), 12 deletions(-)

diff --git a/include/SDL3/SDL_timer.h b/include/SDL3/SDL_timer.h
index b87620409e38..e824ad7f7e09 100644
--- a/include/SDL3/SDL_timer.h
+++ b/include/SDL3/SDL_timer.h
@@ -137,7 +137,7 @@ typedef Uint32 (SDLCALL *SDL_TimerCallback)(Uint32 interval, void *param);
 /**
  * Definition of the timer ID type.
  */
-typedef int SDL_TimerID;
+typedef Uint32 SDL_TimerID;
 
 /**
  * Call a callback function at a future time.
diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c
index 30babaac2710..28cab901a195 100644
--- a/src/timer/SDL_timer.c
+++ b/src/timer/SDL_timer.c
@@ -29,7 +29,7 @@
 
 typedef struct SDL_Timer
 {
-    int timerID;
+    SDL_TimerID timerID;
     SDL_TimerCallback callback;
     void *param;
     Uint64 interval;
@@ -40,7 +40,7 @@ typedef struct SDL_Timer
 
 typedef struct SDL_TimerMap
 {
-    int timerID;
+    SDL_TimerID timerID;
     SDL_Timer *timer;
     struct SDL_TimerMap *next;
 } SDL_TimerMap;
@@ -50,7 +50,6 @@ typedef struct
 {
     /* Data used by the main thread */
     SDL_Thread *thread;
-    SDL_AtomicInt nextID;
     SDL_TimerMap *timermap;
     SDL_Mutex *timermap_lock;
 
@@ -227,8 +226,6 @@ int SDL_InitTimers(void)
             SDL_QuitTimers();
             return -1;
         }
-
-        SDL_AtomicSet(&data->nextID, 1);
     }
     return 0;
 }
@@ -300,7 +297,7 @@ SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *para
             return 0;
         }
     }
-    timer->timerID = SDL_AtomicIncRef(&data->nextID);
+    timer->timerID = SDL_GetNextObjectID();
     timer->callback = callback;
     timer->param = param;
     timer->interval = SDL_MS_TO_NS(interval);
@@ -370,7 +367,7 @@ SDL_bool SDL_RemoveTimer(SDL_TimerID id)
 
 typedef struct SDL_TimerMap
 {
-    int timerID;
+    SDL_TimerID timerID;
     int timeoutID;
     Uint32 interval;
     SDL_TimerCallback callback;
@@ -380,7 +377,6 @@ typedef struct SDL_TimerMap
 
 typedef struct
 {
-    int nextID;
     SDL_TimerMap *timermap;
 } SDL_TimerData;
 
@@ -423,7 +419,7 @@ SDL_TimerID SDL_AddTimer(Uint32 interval, SDL_TimerCallback callback, void *para
     if (!entry) {
         return 0;
     }
-    entry->timerID = ++data->nextID;
+    entry->timerID = SDL_GetNextObjectID();
     entry->callback = callback;
     entry->param = param;
     entry->interval = interval;
diff --git a/test/testautomation_timer.c b/test/testautomation_timer.c
index d7d6449e2d12..e2925e97ef0a 100644
--- a/test/testautomation_timer.c
+++ b/test/testautomation_timer.c
@@ -131,7 +131,7 @@ static int timer_addRemoveTimer(void *arg)
     /* Set timer with a long delay */
     id = SDL_AddTimer(10000, timerTestCallback, NULL);
     SDLTest_AssertPass("Call to SDL_AddTimer(10000,...)");
-    SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
+    SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %" SDL_PRIu32, id);
 
     /* Remove timer again and check that callback was not called */
     result = SDL_RemoveTimer(id);
@@ -153,7 +153,7 @@ static int timer_addRemoveTimer(void *arg)
     /* Set timer with a short delay */
     id = SDL_AddTimer(10, timerTestCallback, (void *)&param);
     SDLTest_AssertPass("Call to SDL_AddTimer(10, param)");
-    SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %d", id);
+    SDLTest_AssertCheck(id > 0, "Check result value, expected: >0, got: %" SDL_PRIu32, id);
 
     /* Wait to let timer trigger callback */
     SDL_Delay(100);