src/timer/riscos/SDL_systimer.c
branchSDL-1.3
changeset 1662 782fd950bd46
parent 1635 92947e3a18db
child 1668 4da1ee79c9af
     1.1 --- a/src/timer/riscos/SDL_systimer.c	Sun May 21 17:27:13 2006 +0000
     1.2 +++ b/src/timer/riscos/SDL_systimer.c	Sun May 28 13:04:16 2006 +0000
     1.3 @@ -37,144 +37,154 @@
     1.4  /* Timer  SDL_arraysize(Timer ),start/reset time */
     1.5  static Uint32 timerStart;
     1.6  /* Timer running function */
     1.7 -void RISCOS_CheckTimer();
     1.8 +void RISCOS_CheckTimer ();
     1.9  #else
    1.10  #include <pthread.h>
    1.11  extern Uint32 riscos_main_thread;
    1.12  extern int riscos_using_threads;
    1.13 -extern Uint32 SDL_ThreadID();
    1.14 -extern Uint32 SDL_EventThreadID(void);
    1.15 +extern Uint32 SDL_ThreadID ();
    1.16 +extern Uint32 SDL_EventThreadID (void);
    1.17  #endif
    1.18  
    1.19  
    1.20 -extern void RISCOS_BackgroundTasks(void);
    1.21 +extern void RISCOS_BackgroundTasks (void);
    1.22  
    1.23  /* The first ticks value of the application */
    1.24  clock_t start;
    1.25  
    1.26 -void SDL_StartTicks(void)
    1.27 +void
    1.28 +SDL_StartTicks (void)
    1.29  {
    1.30 -	/* Set first ticks value */
    1.31 -	start = clock();
    1.32 +    /* Set first ticks value */
    1.33 +    start = clock ();
    1.34  }
    1.35  
    1.36 -Uint32 SDL_GetTicks (void)
    1.37 +Uint32
    1.38 +SDL_GetTicks (void)
    1.39  {
    1.40 -	clock_t ticks;
    1.41 +    clock_t ticks;
    1.42  
    1.43 -	ticks=clock()-start;
    1.44 +    ticks = clock () - start;
    1.45  
    1.46  
    1.47  #if CLOCKS_PER_SEC == 1000
    1.48  
    1.49 -	return(ticks);
    1.50 +    return (ticks);
    1.51  
    1.52  #elif CLOCKS_PER_SEC == 100
    1.53  
    1.54 -	return (ticks * 10);
    1.55 +    return (ticks * 10);
    1.56  
    1.57  #else
    1.58  
    1.59 -	return ticks*(1000/CLOCKS_PER_SEC);
    1.60 +    return ticks * (1000 / CLOCKS_PER_SEC);
    1.61  
    1.62  #endif
    1.63  
    1.64  }
    1.65  
    1.66 -void SDL_Delay (Uint32 ms)
    1.67 +void
    1.68 +SDL_Delay (Uint32 ms)
    1.69  {
    1.70 -    Uint32 now,then,elapsed;
    1.71 +    Uint32 now, then, elapsed;
    1.72  #if !SDL_THREADS_DISABLED
    1.73      int is_event_thread;
    1.74 -    if (riscos_using_threads)
    1.75 -    {
    1.76 -       is_event_thread = 0;
    1.77 -       if (SDL_EventThreadID())
    1.78 -       {
    1.79 -          if (SDL_EventThreadID() == SDL_ThreadID()) is_event_thread = 1;
    1.80 -       } else if (SDL_ThreadID() == riscos_main_thread) is_event_thread = 1;
    1.81 -    } else is_event_thread = 1;
    1.82 +    if (riscos_using_threads) {
    1.83 +        is_event_thread = 0;
    1.84 +        if (SDL_EventThreadID ()) {
    1.85 +            if (SDL_EventThreadID () == SDL_ThreadID ())
    1.86 +                is_event_thread = 1;
    1.87 +        } else if (SDL_ThreadID () == riscos_main_thread)
    1.88 +            is_event_thread = 1;
    1.89 +    } else
    1.90 +        is_event_thread = 1;
    1.91  #endif
    1.92  
    1.93 -        /*TODO: Next version of Unixlib may allow us to use usleep here */
    1.94 -        /*      for non event threads */
    1.95 +    /*TODO: Next version of Unixlib may allow us to use usleep here */
    1.96 +    /*      for non event threads */
    1.97  
    1.98 -	/* Set the timeout interval - Linux only needs to do this once */
    1.99 -	then = SDL_GetTicks();
   1.100 +    /* Set the timeout interval - Linux only needs to do this once */
   1.101 +    then = SDL_GetTicks ();
   1.102  
   1.103 -	do {
   1.104 -		/* Do background tasks required while sleeping as we are not multithreaded */
   1.105 +    do {
   1.106 +        /* Do background tasks required while sleeping as we are not multithreaded */
   1.107  #if SDL_THREADS_DISABLED
   1.108 -		RISCOS_BackgroundTasks();
   1.109 +        RISCOS_BackgroundTasks ();
   1.110  #else
   1.111 -		/* For threaded build only run background tasks in event thread */
   1.112 -		if (is_event_thread) RISCOS_BackgroundTasks();
   1.113 +        /* For threaded build only run background tasks in event thread */
   1.114 +        if (is_event_thread)
   1.115 +            RISCOS_BackgroundTasks ();
   1.116  #endif
   1.117  
   1.118 -		/* Calculate the time interval left (in case of interrupt) */
   1.119 -		now = SDL_GetTicks();
   1.120 -		elapsed = (now-then);
   1.121 -		then = now;
   1.122 -		if ( elapsed >= ms ) {
   1.123 -			break;
   1.124 -		}
   1.125 -		ms -= elapsed;
   1.126 +        /* Calculate the time interval left (in case of interrupt) */
   1.127 +        now = SDL_GetTicks ();
   1.128 +        elapsed = (now - then);
   1.129 +        then = now;
   1.130 +        if (elapsed >= ms) {
   1.131 +            break;
   1.132 +        }
   1.133 +        ms -= elapsed;
   1.134  #if !SDL_THREADS_DISABLED
   1.135 -            /* Need to yield to let other threads have a go */
   1.136 -            if (riscos_using_threads) pthread_yield();
   1.137 +        /* Need to yield to let other threads have a go */
   1.138 +        if (riscos_using_threads)
   1.139 +            pthread_yield ();
   1.140  #endif
   1.141  
   1.142 -	} while ( 1 );
   1.143 +    }
   1.144 +    while (1);
   1.145  }
   1.146  
   1.147  #if SDL_THREADS_DISABLED
   1.148  
   1.149  /* Non-threaded version of timer */
   1.150  
   1.151 -int SDL_SYS_TimerInit(void)
   1.152 +int
   1.153 +SDL_SYS_TimerInit (void)
   1.154  {
   1.155 -	return(0);
   1.156 +    return (0);
   1.157  }
   1.158  
   1.159 -void SDL_SYS_TimerQuit(void)
   1.160 +void
   1.161 +SDL_SYS_TimerQuit (void)
   1.162  {
   1.163 -	SDL_SetTimer(0, NULL);
   1.164 +    SDL_SetTimer (0, NULL);
   1.165  }
   1.166  
   1.167 -int SDL_SYS_StartTimer(void)
   1.168 +int
   1.169 +SDL_SYS_StartTimer (void)
   1.170  {
   1.171 -	timerStart = SDL_GetTicks();
   1.172 +    timerStart = SDL_GetTicks ();
   1.173  
   1.174 -	return(0);
   1.175 +    return (0);
   1.176  }
   1.177  
   1.178 -void SDL_SYS_StopTimer(void)
   1.179 +void
   1.180 +SDL_SYS_StopTimer (void)
   1.181  {
   1.182 -	/* Don't need to do anything as we use SDL_timer_running
   1.183 -	   to detect if we need to check the timer */
   1.184 +    /* Don't need to do anything as we use SDL_timer_running
   1.185 +       to detect if we need to check the timer */
   1.186  }
   1.187  
   1.188  
   1.189 -void RISCOS_CheckTimer()
   1.190 +void
   1.191 +RISCOS_CheckTimer ()
   1.192  {
   1.193 -	if (SDL_timer_running && SDL_GetTicks() - timerStart >= SDL_alarm_interval)
   1.194 -	{
   1.195 -		Uint32 ms;
   1.196 +    if (SDL_timer_running
   1.197 +        && SDL_GetTicks () - timerStart >= SDL_alarm_interval) {
   1.198 +        Uint32 ms;
   1.199  
   1.200 -		ms = SDL_alarm_callback(SDL_alarm_interval);
   1.201 -		if ( ms != SDL_alarm_interval )
   1.202 -		{
   1.203 -			if ( ms )
   1.204 -			{
   1.205 -				SDL_alarm_interval = ROUND_RESOLUTION(ms);
   1.206 -			} else
   1.207 -			{
   1.208 -				SDL_alarm_interval = 0;
   1.209 -				SDL_timer_running = 0;
   1.210 -			}
   1.211 -		}
   1.212 -		if (SDL_alarm_interval) timerStart = SDL_GetTicks();
   1.213 -	}
   1.214 +        ms = SDL_alarm_callback (SDL_alarm_interval);
   1.215 +        if (ms != SDL_alarm_interval) {
   1.216 +            if (ms) {
   1.217 +                SDL_alarm_interval = ROUND_RESOLUTION (ms);
   1.218 +            } else {
   1.219 +                SDL_alarm_interval = 0;
   1.220 +                SDL_timer_running = 0;
   1.221 +            }
   1.222 +        }
   1.223 +        if (SDL_alarm_interval)
   1.224 +            timerStart = SDL_GetTicks ();
   1.225 +    }
   1.226  }
   1.227  
   1.228  #else
   1.229 @@ -187,47 +197,53 @@
   1.230  static int timer_alive = 0;
   1.231  static SDL_Thread *timer = NULL;
   1.232  
   1.233 -static int RunTimer(void *unused)
   1.234 +static int
   1.235 +RunTimer (void *unused)
   1.236  {
   1.237 -	while ( timer_alive ) {
   1.238 -		if ( SDL_timer_running ) {
   1.239 -			SDL_ThreadedTimerCheck();
   1.240 -		}
   1.241 -		SDL_Delay(1);
   1.242 -	}
   1.243 -	return(0);
   1.244 +    while (timer_alive) {
   1.245 +        if (SDL_timer_running) {
   1.246 +            SDL_ThreadedTimerCheck ();
   1.247 +        }
   1.248 +        SDL_Delay (1);
   1.249 +    }
   1.250 +    return (0);
   1.251  }
   1.252  
   1.253  /* This is only called if the event thread is not running */
   1.254 -int SDL_SYS_TimerInit(void)
   1.255 +int
   1.256 +SDL_SYS_TimerInit (void)
   1.257  {
   1.258 -	timer_alive = 1;
   1.259 -	timer = SDL_CreateThread(RunTimer, NULL);
   1.260 -	if ( timer == NULL )
   1.261 -		return(-1);
   1.262 -	return(SDL_SetTimerThreaded(1));
   1.263 +    timer_alive = 1;
   1.264 +    timer = SDL_CreateThread (RunTimer, NULL);
   1.265 +    if (timer == NULL)
   1.266 +        return (-1);
   1.267 +    return (SDL_SetTimerThreaded (1));
   1.268  }
   1.269  
   1.270 -void SDL_SYS_TimerQuit(void)
   1.271 +void
   1.272 +SDL_SYS_TimerQuit (void)
   1.273  {
   1.274 -	timer_alive = 0;
   1.275 -	if ( timer ) {
   1.276 -		SDL_WaitThread(timer, NULL);
   1.277 -		timer = NULL;
   1.278 -	}
   1.279 +    timer_alive = 0;
   1.280 +    if (timer) {
   1.281 +        SDL_WaitThread (timer, NULL);
   1.282 +        timer = NULL;
   1.283 +    }
   1.284  }
   1.285  
   1.286 -int SDL_SYS_StartTimer(void)
   1.287 +int
   1.288 +SDL_SYS_StartTimer (void)
   1.289  {
   1.290 -	SDL_SetError("Internal logic error: RISC OS uses threaded timer");
   1.291 -	return(-1);
   1.292 +    SDL_SetError ("Internal logic error: RISC OS uses threaded timer");
   1.293 +    return (-1);
   1.294  }
   1.295  
   1.296 -void SDL_SYS_StopTimer(void)
   1.297 +void
   1.298 +SDL_SYS_StopTimer (void)
   1.299  {
   1.300 -	return;
   1.301 +    return;
   1.302  }
   1.303  
   1.304  #endif /* SDL_THREADS_DISABLED */
   1.305  
   1.306  #endif /* SDL_TIMER_RISCOS */
   1.307 +/* vi: set ts=4 sw=4 expandtab: */