src/timer/dummy/SDL_systimer.c
author Sam Lantinga
Mon, 10 Jul 2006 21:04:37 +0000
changeset 1895 c121d94672cb
parent 1635 92947e3a18db
child 2859 99210400e8b9
permissions -rw-r--r--
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
slouken@1361
     1
/*
slouken@1361
     2
    SDL - Simple DirectMedia Layer
slouken@1361
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@1361
     4
slouken@1361
     5
    This library is free software; you can redistribute it and/or
slouken@1361
     6
    modify it under the terms of the GNU Lesser General Public
slouken@1361
     7
    License as published by the Free Software Foundation; either
slouken@1361
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@1361
     9
slouken@1361
    10
    This library is distributed in the hope that it will be useful,
slouken@1361
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@1361
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1361
    13
    Lesser General Public License for more details.
slouken@1361
    14
slouken@1361
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1361
    16
    License along with this library; if not, write to the Free Software
slouken@1361
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@1361
    18
slouken@1361
    19
    Sam Lantinga
slouken@1361
    20
    slouken@libsdl.org
slouken@1361
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@1361
    23
slouken@1635
    24
#if defined(SDL_TIMER_DUMMY) || defined(SDL_TIMERS_DISABLED)
slouken@1635
    25
slouken@1484
    26
#include "SDL_timer.h"
slouken@1484
    27
#include "../SDL_timer_c.h"
slouken@1484
    28
slouken@1895
    29
void
slouken@1895
    30
SDL_StartTicks(void)
slouken@1361
    31
{
slouken@1361
    32
}
slouken@1361
    33
slouken@1895
    34
Uint32
slouken@1895
    35
SDL_GetTicks(void)
slouken@1361
    36
{
slouken@1895
    37
    SDL_Unsupported();
slouken@1895
    38
    return 0;
slouken@1361
    39
}
slouken@1361
    40
slouken@1895
    41
void
slouken@1895
    42
SDL_Delay(Uint32 ms)
slouken@1361
    43
{
slouken@1895
    44
    SDL_Unsupported();
slouken@1361
    45
}
slouken@1361
    46
slouken@1361
    47
#include "SDL_thread.h"
slouken@1361
    48
slouken@1361
    49
/* Data to handle a single periodic alarm */
slouken@1361
    50
static int timer_alive = 0;
slouken@1361
    51
static SDL_Thread *timer = NULL;
slouken@1361
    52
slouken@1895
    53
static int
slouken@1895
    54
RunTimer(void *unused)
slouken@1361
    55
{
slouken@1895
    56
    while (timer_alive) {
slouken@1895
    57
        if (SDL_timer_running) {
slouken@1895
    58
            SDL_ThreadedTimerCheck();
slouken@1895
    59
        }
slouken@1895
    60
        SDL_Delay(1);
slouken@1895
    61
    }
slouken@1895
    62
    return (0);
slouken@1361
    63
}
slouken@1361
    64
slouken@1361
    65
/* This is only called if the event thread is not running */
slouken@1895
    66
int
slouken@1895
    67
SDL_SYS_TimerInit(void)
slouken@1361
    68
{
slouken@1895
    69
    timer_alive = 1;
slouken@1895
    70
    timer = SDL_CreateThread(RunTimer, NULL);
slouken@1895
    71
    if (timer == NULL)
slouken@1895
    72
        return (-1);
slouken@1895
    73
    return (SDL_SetTimerThreaded(1));
slouken@1361
    74
}
slouken@1361
    75
slouken@1895
    76
void
slouken@1895
    77
SDL_SYS_TimerQuit(void)
slouken@1361
    78
{
slouken@1895
    79
    timer_alive = 0;
slouken@1895
    80
    if (timer) {
slouken@1895
    81
        SDL_WaitThread(timer, NULL);
slouken@1895
    82
        timer = NULL;
slouken@1895
    83
    }
slouken@1361
    84
}
slouken@1361
    85
slouken@1895
    86
int
slouken@1895
    87
SDL_SYS_StartTimer(void)
slouken@1361
    88
{
slouken@1895
    89
    SDL_SetError("Internal logic error: threaded timer in use");
slouken@1895
    90
    return (-1);
slouken@1361
    91
}
slouken@1361
    92
slouken@1895
    93
void
slouken@1895
    94
SDL_SYS_StopTimer(void)
slouken@1361
    95
{
slouken@1895
    96
    return;
slouken@1361
    97
}
slouken@1635
    98
slouken@1635
    99
#endif /* SDL_TIMER_DUMMY || SDL_TIMERS_DISABLED */
slouken@1895
   100
/* vi: set ts=4 sw=4 expandtab: */