FSCORE-643 Windows: Add start parameter -monotonic-clock, replaces build flag WIN32_MONOTONIC

This commit is contained in:
Jeff Lenk 2010-07-28 20:44:45 -05:00
parent b80eb9fb13
commit 3515c7a020
3 changed files with 27 additions and 7 deletions

View File

@ -251,7 +251,8 @@ typedef enum {
SCF_CALIBRATE_CLOCK = (1 << 8), SCF_CALIBRATE_CLOCK = (1 << 8),
SCF_USE_HEAVY_TIMING = (1 << 9), SCF_USE_HEAVY_TIMING = (1 << 9),
SCF_USE_CLOCK_RT = (1 << 10), SCF_USE_CLOCK_RT = (1 << 10),
SCF_VERBOSE_EVENTS = (1 << 11) SCF_VERBOSE_EVENTS = (1 << 11),
SCF_USE_WIN32_MONOTONIC = (1 << 12)
} switch_core_flag_enum_t; } switch_core_flag_enum_t;
typedef uint32_t switch_core_flag_t; typedef uint32_t switch_core_flag_t;

View File

@ -62,6 +62,7 @@ static char *pfile = PIDFILE;
#define SERVICENAME_DEFAULT "FreeSWITCH" #define SERVICENAME_DEFAULT "FreeSWITCH"
#define SERVICENAME_MAXLEN 256 #define SERVICENAME_MAXLEN 256
static char service_name[SERVICENAME_MAXLEN]; static char service_name[SERVICENAME_MAXLEN];
static switch_core_flag_t service_flags = SCF_NONE;
#include <winsock2.h> #include <winsock2.h>
#include <windows.h> #include <windows.h>
@ -174,6 +175,11 @@ void WINAPI service_main(DWORD numArgs, char **args)
{ {
switch_core_flag_t flags = SCF_USE_SQL | SCF_USE_AUTO_NAT | SCF_CALIBRATE_CLOCK | SCF_USE_CLOCK_RT; switch_core_flag_t flags = SCF_USE_SQL | SCF_USE_AUTO_NAT | SCF_CALIBRATE_CLOCK | SCF_USE_CLOCK_RT;
const char *err = NULL; /* error value for return from freeswitch initialization */ const char *err = NULL; /* error value for return from freeswitch initialization */
/* Override flags if they have been set earlier */
if (service_flags != SCF_NONE)
flags = service_flags;
/* we have to initialize the service-specific stuff */ /* we have to initialize the service-specific stuff */
memset(&status, 0, sizeof(SERVICE_STATUS)); memset(&status, 0, sizeof(SERVICE_STATUS));
status.dwServiceType = SERVICE_WIN32; status.dwServiceType = SERVICE_WIN32;
@ -319,6 +325,7 @@ int main(int argc, char *argv[])
"\t-service [name] -- start freeswitch as a service, cannot be used if loaded as a console app\n" "\t-service [name] -- start freeswitch as a service, cannot be used if loaded as a console app\n"
"\t-install [name] -- install freeswitch as a service, with optional service name\n" "\t-install [name] -- install freeswitch as a service, with optional service name\n"
"\t-uninstall -- remove freeswitch as a service\n" "\t-uninstall -- remove freeswitch as a service\n"
"\t-monotonic-clock -- use monotonic clock as timer source\n"
#else #else
"\t-nf -- no forking\n" "\t-nf -- no forking\n"
"\t-u [user] -- specify user to switch to\n" "\t-g [group] -- specify group to switch to\n" "\t-u [user] -- specify user to switch to\n" "\t-g [group] -- specify group to switch to\n"
@ -427,6 +434,11 @@ int main(int argc, char *argv[])
} }
} }
} }
if (local_argv[x] && !strcmp(local_argv[x], "-monotonic-clock")) {
flags |= SCF_USE_WIN32_MONOTONIC;
known_opt++;
}
#else #else
if (local_argv[x] && !strcmp(local_argv[x], "-u")) { if (local_argv[x] && !strcmp(local_argv[x], "-u")) {
x++; x++;
@ -732,6 +744,8 @@ int main(int argc, char *argv[])
, ,
{NULL, NULL} {NULL, NULL}
}; };
service_flags = flags; /* copy parsed flags for service startup */
if (StartServiceCtrlDispatcher(dispatchTable) == 0) { if (StartServiceCtrlDispatcher(dispatchTable) == 0) {
/* Not loaded as a service */ /* Not loaded as a service */
fprintf(stderr, "Error Freeswitch loaded as a console app with -service option\n"); fprintf(stderr, "Error Freeswitch loaded as a console app with -service option\n");

View File

@ -48,10 +48,11 @@
#define MAX_ELEMENTS 3600 #define MAX_ELEMENTS 3600
#define IDLE_SPEED 100 #define IDLE_SPEED 100
/* For now enable WIN32_MONOTONIC on Windows 2003 Server and Windows XP systems for improved timer support */ /* In Windows, enable the montonic timer for better timer accuracy on Windows 2003 Server, XP and older */
/* GetSystemTimeAsFileTime does not update on timeBeginPeriod on these OS */ /* GetSystemTimeAsFileTime does not update on timeBeginPeriod on these OS. */
/* we leave the normal timer support as the default for now */ /* Flag SCF_USE_WIN32_MONOTONIC must be enabled to activate it (start parameter -monotonic-clock) */
#if (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)) || defined(WIN32_MONOTONIC)
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
static int MONO = 1; static int MONO = 1;
#else #else
static int MONO = 0; static int MONO = 0;
@ -344,7 +345,7 @@ static switch_time_t time_now(int64_t offset)
{ {
switch_time_t now; switch_time_t now;
#if (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)) || defined(WIN32_MONOTONIC) #if (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)) || defined(WIN32)
if (MONO) { if (MONO) {
#ifndef WIN32 #ifndef WIN32
struct timespec ts; struct timespec ts;
@ -375,7 +376,7 @@ static switch_time_t time_now(int64_t offset)
#endif #endif
now = switch_time_now(); now = switch_time_now();
#if (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)) || defined(WIN32_MONOTONIC) #if (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)) || defined(WIN32)
} }
#endif #endif
@ -1074,6 +1075,10 @@ SWITCH_MODULE_LOAD_FUNCTION(softtimer_load)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Clock calibration disabled.\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Clock calibration disabled.\n");
} }
if (switch_test_flag((&runtime), SCF_USE_WIN32_MONOTONIC)) {
MONO = 1;
}
/* indicate that the module should continue to be loaded */ /* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }