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