summaryrefslogtreecommitdiff
path: root/lib/ultralib/src/os/stoptimer.c
blob: 8688d6f3665e39e290e6d8bcd8fac51591170dc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "PR/os_internal.h"
#include "PR/ultraerror.h"
#include "PRinternal/osint.h"
#include "PRinternal/viint.h"

int osStopTimer(OSTimer* t) {
    register u32 savedMask;
    OSTimer* timep;

#ifdef _DEBUG
    if (!__osViDevMgr.active) {
        __osError(ERR_OSSTOPTIMER, 0);
        return 0;
    }
#endif

    if (t->next == NULL) {
        return -1;
    }

    savedMask = __osDisableInt();
    timep = t->next;

    if (timep != __osTimerList) {
        timep->value += t->value;
    }

    t->prev->next = t->next;
    t->next->prev = t->prev;
    t->next = NULL;
    t->prev = NULL;

    if (__osTimerList->next == __osTimerList) {
        __osSetCompare(0);
    }

    __osRestoreInt(savedMask);
    return 0;
}