src/timer/SDL_timer.c
changeset 5115 427998ff3bcf
parent 5114 e337f792c6a7
child 5262 b530ef003506
equal deleted inserted replaced
5114:e337f792c6a7 5115:427998ff3bcf
    22 #include "SDL_config.h"
    22 #include "SDL_config.h"
    23 
    23 
    24 #include "SDL_timer.h"
    24 #include "SDL_timer.h"
    25 #include "SDL_timer_c.h"
    25 #include "SDL_timer_c.h"
    26 #include "SDL_atomic.h"
    26 #include "SDL_atomic.h"
       
    27 #include "SDL_cpuinfo.h"
    27 #include "SDL_thread.h"
    28 #include "SDL_thread.h"
    28 
    29 
    29 /* #define DEBUG_TIMERS */
    30 /* #define DEBUG_TIMERS */
    30 
    31 
    31 typedef struct _SDL_Timer
    32 typedef struct _SDL_Timer
    44     int timerID;
    45     int timerID;
    45     SDL_Timer *timer;
    46     SDL_Timer *timer;
    46     struct _SDL_TimerMap *next;
    47     struct _SDL_TimerMap *next;
    47 } SDL_TimerMap;
    48 } SDL_TimerMap;
    48 
    49 
    49 /* A reasonable guess */
       
    50 #define CACHELINE_SIZE  128
       
    51 
       
    52 /* The timers are kept in a sorted list */
    50 /* The timers are kept in a sorted list */
    53 typedef struct {
    51 typedef struct {
    54     /* Data used by the main thread */
    52     /* Data used by the main thread */
    55     SDL_Thread *thread;
    53     SDL_Thread *thread;
    56     SDL_atomic_t nextID;
    54     SDL_atomic_t nextID;
    57     SDL_TimerMap *timermap;
    55     SDL_TimerMap *timermap;
    58     SDL_mutex *timermap_lock;
    56     SDL_mutex *timermap_lock;
    59 
    57 
    60     /* Padding to separate cache lines between threads */
    58     /* Padding to separate cache lines between threads */
    61     char pad[CACHELINE_SIZE];
    59     char cache_pad[SDL_CACHELINE_SIZE];
    62 
    60 
    63     /* Data used to communicate with the timer thread */
    61     /* Data used to communicate with the timer thread */
    64     SDL_SpinLock lock;
    62     SDL_SpinLock lock;
    65     SDL_sem *sem;
    63     SDL_sem *sem;
    66     SDL_Timer * volatile pending;
    64     SDL_Timer * volatile pending;