simplified mstimer_now for BSD, Windows, and Linux ports. (#309)
Co-authored-by: Steve Karg <skarg@users.sourceforge.net>
This commit is contained in:
@@ -34,9 +34,6 @@
|
|||||||
#endif
|
#endif
|
||||||
/** @file bsd/timer.c Provides BSD-specific time and timer functions. */
|
/** @file bsd/timer.c Provides BSD-specific time and timer functions. */
|
||||||
|
|
||||||
/* counter for the various timers */
|
|
||||||
static volatile unsigned long Millisecond_Counter;
|
|
||||||
|
|
||||||
/* start time for the clock */
|
/* start time for the clock */
|
||||||
static struct timespec start;
|
static struct timespec start;
|
||||||
/* The timeGetTime function retrieves the system time, in milliseconds.
|
/* The timeGetTime function retrieves the system time, in milliseconds.
|
||||||
@@ -69,16 +66,7 @@ unsigned long timeGetTime(void)
|
|||||||
*/
|
*/
|
||||||
unsigned long mstimer_now(void)
|
unsigned long mstimer_now(void)
|
||||||
{
|
{
|
||||||
unsigned long now = timeGetTime();
|
return timeGetTime();
|
||||||
unsigned long delta_time = 0;
|
|
||||||
|
|
||||||
if (Millisecond_Counter <= now) {
|
|
||||||
delta_time = now - Millisecond_Counter;
|
|
||||||
} else {
|
|
||||||
delta_time = (ULONG_MAX - Millisecond_Counter) + now + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return delta_time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -32,9 +32,6 @@
|
|||||||
|
|
||||||
/** @file linux/mstimer.c Provides Linux-specific time and timer functions. */
|
/** @file linux/mstimer.c Provides Linux-specific time and timer functions. */
|
||||||
|
|
||||||
/* counter for the various timers */
|
|
||||||
static volatile unsigned long Millisecond_Counter;
|
|
||||||
|
|
||||||
/* start time for the clock */
|
/* start time for the clock */
|
||||||
static struct timespec start;
|
static struct timespec start;
|
||||||
|
|
||||||
@@ -60,16 +57,7 @@ static unsigned long timeGetTime(void)
|
|||||||
*/
|
*/
|
||||||
unsigned long mstimer_now(void)
|
unsigned long mstimer_now(void)
|
||||||
{
|
{
|
||||||
unsigned long now = timeGetTime();
|
return timeGetTime();
|
||||||
unsigned long delta_time = 0;
|
|
||||||
|
|
||||||
if (Millisecond_Counter <= now) {
|
|
||||||
delta_time = now - Millisecond_Counter;
|
|
||||||
} else {
|
|
||||||
delta_time = (ULONG_MAX - Millisecond_Counter) + now + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return delta_time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -32,9 +32,6 @@
|
|||||||
#include "bacport.h"
|
#include "bacport.h"
|
||||||
#include "bacnet/basic/sys/mstimer.h"
|
#include "bacnet/basic/sys/mstimer.h"
|
||||||
|
|
||||||
/* counter for the various timers */
|
|
||||||
static volatile unsigned long Millisecond_Counter;
|
|
||||||
|
|
||||||
/* Windows timer period - in milliseconds */
|
/* Windows timer period - in milliseconds */
|
||||||
static unsigned long Timer_Period = 1;
|
static unsigned long Timer_Period = 1;
|
||||||
|
|
||||||
@@ -44,16 +41,7 @@ static unsigned long Timer_Period = 1;
|
|||||||
*/
|
*/
|
||||||
unsigned long mstimer_now(void)
|
unsigned long mstimer_now(void)
|
||||||
{
|
{
|
||||||
unsigned long now = timeGetTime();
|
return timeGetTime();
|
||||||
unsigned long delta_time = 0;
|
|
||||||
|
|
||||||
if (Millisecond_Counter <= now) {
|
|
||||||
delta_time = now - Millisecond_Counter;
|
|
||||||
} else {
|
|
||||||
delta_time = (ULONG_MAX - Millisecond_Counter) + now + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return delta_time;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user