-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeout.c
76 lines (63 loc) · 1.68 KB
/
Timeout.c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
////////////////////////////////////////////////////////////////////////////////
//
// Global including files.
//
// Including the files for the system.
//
// These including files are generally used in different operation system.
//
////////////////////////////////////////////////////////////////////////////////
#include "Global.h"
////////////////////////////////////////////////////////////////////////////////
//
// Initialize timeout.
//
////////////////////////////////////////////////////////////////////////////////
void InitializeTimeout(SimpleTimeout* pTimeout)
{
#ifdef _DEBUG
assert(pTimeout != NULL);
#endif
//Clear timeout.
memset(pTimeout,0,sizeof(SimpleTimeout));
//Initialize open time.
assert(InitializeTime(&pTimeout->timeOpen));
//Set last time.
pTimeout->timeLast = GetMilliseconds();
//Set consumed time.
pTimeout->timeConsumed = NEVER_TIMEOUT;
}
////////////////////////////////////////////////////////////////////////////////
//
// Is timeout.
//
////////////////////////////////////////////////////////////////////////////////
_BOOL IsTimeout(SimpleTimeout* pTimeout)
{
#ifdef _DEBUG
assert(pTimeout != NULL);
#endif
//Check consumed time.
if(pTimeout->timeConsumed != NEVER_TIMEOUT)
{
//Check timeout.
if(GetMilliseconds() >= (pTimeout->timeLast + pTimeout->timeConsumed))
{
return _TRUE;
}
}
return _FALSE;
}
////////////////////////////////////////////////////////////////////////////////
//
// Reset timeout.
//
////////////////////////////////////////////////////////////////////////////////
void ResetTimeout(SimpleTimeout* pTimeout)
{
#ifdef _DEBUG
assert(pTimeout != NULL);
#endif
//Set last time.
pTimeout->timeLast = GetMilliseconds();
}