]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FSCORE-643 Windows: Add start parameter -monotonic-clock, replaces build flag WIN32_M...
authorJeff Lenk <jeff@jefflenk.com>
Thu, 29 Jul 2010 01:44:45 +0000 (20:44 -0500)
committerJeff Lenk <jeff@jefflenk.com>
Thu, 29 Jul 2010 01:44:45 +0000 (20:44 -0500)
src/include/switch_types.h
src/switch.c
src/switch_time.c

index 7752c4fbef838b23a9ee685454b55c4badc58edb..1808aa167ec1b13d0dbab428d275007ec24a5f79 100644 (file)
@@ -251,7 +251,8 @@ typedef enum {
        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;
 
index 77aea8dc00d794b43cbc91a1a3c6f5b9c52c6eba..a28baba6f076028fb243430a56d3becbade48b6b 100644 (file)
@@ -62,6 +62,7 @@ static char *pfile = PIDFILE;
 #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>
 
@@ -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;
        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;
@@ -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-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"
@@ -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
                if (local_argv[x] && !strcmp(local_argv[x], "-u")) {
                        x++;
@@ -732,6 +744,8 @@ int main(int argc, char *argv[])
                                ,
                                {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");
index 5e93d59261c65738da4c41851fd3970f74b15b3c..5c07409d93ce0b3a8dc900910f2aa580d19f2cc3 100644 (file)
 #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;
@@ -344,7 +345,7 @@ static switch_time_t time_now(int64_t offset)
 {
        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;
@@ -375,7 +376,7 @@ static switch_time_t time_now(int64_t offset)
 #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
 
@@ -1074,6 +1075,10 @@ SWITCH_MODULE_LOAD_FUNCTION(softtimer_load)
                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;
 }