SCF_CALIBRATE_CLOCK = (1 << 8),
SCF_USE_HEAVY_TIMING = (1 << 9),
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;
typedef uint32_t switch_core_flag_t;
#define SERVICENAME_DEFAULT "FreeSWITCH"
#define SERVICENAME_MAXLEN 256
static char service_name[SERVICENAME_MAXLEN];
+static switch_core_flag_t service_flags = SCF_NONE;
#include <winsock2.h>
#include <windows.h>
{
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 */
+
+ /* Override flags if they have been set earlier */
+ if (service_flags != SCF_NONE)
+ flags = service_flags;
+
/* we have to initialize the service-specific stuff */
memset(&status, 0, sizeof(SERVICE_STATUS));
status.dwServiceType = SERVICE_WIN32;
"\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-uninstall -- remove freeswitch as a service\n"
+ "\t-monotonic-clock -- use monotonic clock as timer source\n"
#else
"\t-nf -- no forking\n"
"\t-u [user] -- specify user to switch to\n" "\t-g [group] -- specify group to switch to\n"
}
}
}
+
+ if (local_argv[x] && !strcmp(local_argv[x], "-monotonic-clock")) {
+ flags |= SCF_USE_WIN32_MONOTONIC;
+ known_opt++;
+ }
#else
if (local_argv[x] && !strcmp(local_argv[x], "-u")) {
x++;
,
{NULL, NULL}
};
+ service_flags = flags; /* copy parsed flags for service startup */
+
if (StartServiceCtrlDispatcher(dispatchTable) == 0) {
/* Not loaded as a service */
fprintf(stderr, "Error Freeswitch loaded as a console app with -service option\n");
#define MAX_ELEMENTS 3600
#define IDLE_SPEED 100
-/* For now enable WIN32_MONOTONIC on Windows 2003 Server and Windows XP systems for improved timer support */
-/* GetSystemTimeAsFileTime does not update on timeBeginPeriod on these OS */
-/* we leave the normal timer support as the default for now */
-#if (defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)) || defined(WIN32_MONOTONIC)
+/* 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. */
+/* Flag SCF_USE_WIN32_MONOTONIC must be enabled to activate it (start parameter -monotonic-clock) */
+
+#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
static int MONO = 1;
#else
static int MONO = 0;
{
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) {
#ifndef WIN32
struct timespec ts;
#endif
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
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 */
return SWITCH_STATUS_SUCCESS;
}