mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-02-09 09:17:34 +00:00
FS-10167: Fix to make everything work right with linux again
This commit is contained in:
parent
b41a847b9d
commit
88660290d2
@ -137,6 +137,7 @@ KS_DECLARE(void) ks_random_string(char *buf, uint16_t len, char *set);
|
|||||||
#include "ks_rng.h"
|
#include "ks_rng.h"
|
||||||
#include "ks_acl.h"
|
#include "ks_acl.h"
|
||||||
#include "ks_base64.h"
|
#include "ks_base64.h"
|
||||||
|
#include "ks_time.h"
|
||||||
|
|
||||||
KS_END_EXTERN_C
|
KS_END_EXTERN_C
|
||||||
|
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2007-2014, Anthony Minessale II
|
* Copyright (c) 2007-2014, Anthony Minessale II
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
* modification, are permitted provided that the following conditions
|
* modification, are permitted provided that the following conditions
|
||||||
* are met:
|
* are met:
|
||||||
*
|
*
|
||||||
* * Redistributions of source code must retain the above copyright
|
* * Redistributions of source code must retain the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer.
|
* notice, this list of conditions and the following disclaimer.
|
||||||
*
|
*
|
||||||
* * Redistributions in binary form must reproduce the above copyright
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
* notice, this list of conditions and the following disclaimer in the
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
* documentation and/or other materials provided with the distribution.
|
* documentation and/or other materials provided with the distribution.
|
||||||
*
|
*
|
||||||
* * Neither the name of the original author; nor the names of any contributors
|
* * Neither the name of the original author; nor the names of any contributors
|
||||||
* may be used to endorse or promote products derived from this software
|
* may be used to endorse or promote products derived from this software
|
||||||
* without specific prior written permission.
|
* without specific prior written permission.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||||
@ -88,15 +88,10 @@ static inline void win32_init_timers(void)
|
|||||||
LeaveCriticalSection(&timer_section);
|
LeaveCriticalSection(&timer_section);
|
||||||
}
|
}
|
||||||
|
|
||||||
KS_DECLARE(void) ks_time_init(void)
|
|
||||||
{
|
|
||||||
win32_init_timers();
|
|
||||||
}
|
|
||||||
|
|
||||||
KS_DECLARE(ks_time_t) ks_time_now(void)
|
KS_DECLARE(ks_time_t) ks_time_now(void)
|
||||||
{
|
{
|
||||||
ks_time_t now;
|
ks_time_t now;
|
||||||
|
|
||||||
if (win32_use_qpc) {
|
if (win32_use_qpc) {
|
||||||
/* Use QueryPerformanceCounter */
|
/* Use QueryPerformanceCounter */
|
||||||
uint64_t count = 0;
|
uint64_t count = 0;
|
||||||
@ -106,14 +101,14 @@ KS_DECLARE(ks_time_t) ks_time_now(void)
|
|||||||
/* Use good old timeGetTime() */
|
/* Use good old timeGetTime() */
|
||||||
DWORD tick_now;
|
DWORD tick_now;
|
||||||
DWORD tick_diff;
|
DWORD tick_diff;
|
||||||
|
|
||||||
tick_now = timeGetTime();
|
tick_now = timeGetTime();
|
||||||
if (win32_tick_time_since_start != -1) {
|
if (win32_tick_time_since_start != -1) {
|
||||||
EnterCriticalSection(&timer_section);
|
EnterCriticalSection(&timer_section);
|
||||||
/* just add diff (to make it work more than 50 days). */
|
/* just add diff (to make it work more than 50 days). */
|
||||||
tick_diff = tick_now - win32_last_get_time_tick;
|
tick_diff = tick_now - win32_last_get_time_tick;
|
||||||
win32_tick_time_since_start += tick_diff;
|
win32_tick_time_since_start += tick_diff;
|
||||||
|
|
||||||
win32_last_get_time_tick = tick_now;
|
win32_last_get_time_tick = tick_now;
|
||||||
now = (win32_tick_time_since_start * 1000);
|
now = (win32_tick_time_since_start * 1000);
|
||||||
LeaveCriticalSection(&timer_section);
|
LeaveCriticalSection(&timer_section);
|
||||||
@ -131,7 +126,7 @@ KS_DECLARE(ks_time_t) ks_time_now(void)
|
|||||||
KS_DECLARE(ks_time_t) ks_time_now_sec(void)
|
KS_DECLARE(ks_time_t) ks_time_now_sec(void)
|
||||||
{
|
{
|
||||||
ks_time_t now;
|
ks_time_t now;
|
||||||
|
|
||||||
if (win32_use_qpc) {
|
if (win32_use_qpc) {
|
||||||
/* Use QueryPerformanceCounter */
|
/* Use QueryPerformanceCounter */
|
||||||
uint64_t count = 0;
|
uint64_t count = 0;
|
||||||
@ -141,14 +136,14 @@ KS_DECLARE(ks_time_t) ks_time_now_sec(void)
|
|||||||
/* Use good old timeGetTime() */
|
/* Use good old timeGetTime() */
|
||||||
DWORD tick_now;
|
DWORD tick_now;
|
||||||
DWORD tick_diff;
|
DWORD tick_diff;
|
||||||
|
|
||||||
tick_now = timeGetTime();
|
tick_now = timeGetTime();
|
||||||
if (win32_tick_time_since_start != -1) {
|
if (win32_tick_time_since_start != -1) {
|
||||||
EnterCriticalSection(&timer_section);
|
EnterCriticalSection(&timer_section);
|
||||||
/* just add diff (to make it work more than 50 days). */
|
/* just add diff (to make it work more than 50 days). */
|
||||||
tick_diff = tick_now - win32_last_get_time_tick;
|
tick_diff = tick_now - win32_last_get_time_tick;
|
||||||
win32_tick_time_since_start += tick_diff;
|
win32_tick_time_since_start += tick_diff;
|
||||||
|
|
||||||
win32_last_get_time_tick = tick_now;
|
win32_last_get_time_tick = tick_now;
|
||||||
now = (win32_tick_time_since_start / 1000);
|
now = (win32_tick_time_since_start / 1000);
|
||||||
LeaveCriticalSection(&timer_section);
|
LeaveCriticalSection(&timer_section);
|
||||||
@ -167,15 +162,15 @@ KS_DECLARE(void) ks_sleep(ks_time_t microsec)
|
|||||||
{
|
{
|
||||||
|
|
||||||
LARGE_INTEGER perfCnt, start, now;
|
LARGE_INTEGER perfCnt, start, now;
|
||||||
|
|
||||||
QueryPerformanceFrequency(&perfCnt);
|
QueryPerformanceFrequency(&perfCnt);
|
||||||
QueryPerformanceCounter(&start);
|
QueryPerformanceCounter(&start);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
QueryPerformanceCounter((LARGE_INTEGER*) &now);
|
QueryPerformanceCounter((LARGE_INTEGER*) &now);
|
||||||
SwitchToThread();
|
SwitchToThread();
|
||||||
} while ((now.QuadPart - start.QuadPart) / (float)(perfCnt.QuadPart) * 1000 * 1000 < (DWORD)microsec);
|
} while ((now.QuadPart - start.QuadPart) / (float)(perfCnt.QuadPart) * 1000 * 1000 < (DWORD)microsec);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else //!WINDOWS, UNIX ETC
|
#else //!WINDOWS, UNIX ETC
|
||||||
@ -187,7 +182,7 @@ KS_DECLARE(ks_time_t) ks_time_now(void)
|
|||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
now = (int64_t)ts.tv_sec * 1000000 + ((int64_t)ts.tv_nsec / 1000);
|
now = (int64_t)ts.tv_sec * 1000000 + ((int64_t)ts.tv_nsec / 1000);
|
||||||
#else
|
#else
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
now = tv.tv_sec * 1000000 + tv.tv_usec;
|
now = tv.tv_sec * 1000000 + tv.tv_usec;
|
||||||
@ -204,7 +199,7 @@ KS_DECLARE(ks_time_t) ks_time_now_sec(void)
|
|||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_REALTIME, &ts);
|
clock_gettime(CLOCK_REALTIME, &ts);
|
||||||
now = (int64_t)ts.tv_sec;
|
now = (int64_t)ts.tv_sec;
|
||||||
#else
|
#else
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
now = tv.tv_sec;
|
now = tv.tv_sec;
|
||||||
@ -232,7 +227,7 @@ KS_DECLARE(void) ks_sleep(ks_time_t microsec)
|
|||||||
#if defined(HAVE_CLOCK_NANOSLEEP) || defined(__APPLE__)
|
#if defined(HAVE_CLOCK_NANOSLEEP) || defined(__APPLE__)
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_CLOCK_NANOSLEEP)
|
#if defined(HAVE_CLOCK_NANOSLEEP)
|
||||||
ts.tv_sec = ks_time_sec(microsec);
|
ts.tv_sec = ks_time_sec(microsec);
|
||||||
ts.tv_nsec = ks_time_nsec(microsec);
|
ts.tv_nsec = ks_time_nsec(microsec);
|
||||||
@ -244,15 +239,21 @@ KS_DECLARE(void) ks_sleep(ks_time_t microsec)
|
|||||||
#else
|
#else
|
||||||
generic_sleep(microsec);
|
generic_sleep(microsec);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
sched_yield();
|
sched_yield();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
KS_DECLARE(void) ks_time_init(void)
|
||||||
|
{
|
||||||
|
#ifdef _WINDOWS_
|
||||||
|
win32_init_timers();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
/* For Emacs:
|
/* For Emacs:
|
||||||
* Local Variables:
|
* Local Variables:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user