]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-4220 --resolve i refactored this into a general cross platform function and use...
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 15 May 2012 13:31:33 +0000 (08:31 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Tue, 15 May 2012 13:31:42 +0000 (08:31 -0500)
src/include/switch_core.h
src/mod/endpoints/mod_sofia/sofia.c
src/switch_core.c
src/switch_event.c
src/switch_time.c

index 522ebec1f8a8a38ffceb248a541a690b97b0c3ff..8f9220d0b9818602c7ca8ad88d29e60bf019e983 100644 (file)
@@ -2328,7 +2328,7 @@ SWITCH_DECLARE(switch_status_t) switch_say_file_handle_create(switch_say_file_ha
 SWITCH_DECLARE(void) switch_say_file(switch_say_file_handle_t *sh, const char *fmt, ...);
 SWITCH_DECLARE(int) switch_max_file_desc(void);
 SWITCH_DECLARE(void) switch_close_extra_files(int *keep, int keep_ttl);
-
+SWITCH_DECLARE(switch_status_t) switch_core_thread_set_cpu_affinity(int cpu);
 SWITCH_END_EXTERN_C
 #endif
 /* For Emacs:
index df28e346ae62c787c5193360c49b5eb00280f820..d7dac7581b1e302cfc46229cec7c1b06255bea80 100644 (file)
@@ -1363,15 +1363,7 @@ void *SWITCH_THREAD_FUNC sofia_msg_thread_run(switch_thread_t *thread, void *obj
 
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "MSG Thread %d Started\n", my_id);
 
-#ifdef HAVE_CPU_SET_MACROS
-       {
-               cpu_set_t set;
-               CPU_ZERO(&set);
-               CPU_SET(my_id, &set);
-               sched_setaffinity(0, sizeof(set), &set);                
-       }
-#endif
-
+       switch_core_thread_set_cpu_affinity(my_id);
 
        while(switch_queue_pop(q, &pop) == SWITCH_STATUS_SUCCESS && pop) {
                sofia_dispatch_event_t *de = (sofia_dispatch_event_t *) pop;
index f957a7ae5ecf92193729ff352fed2584c6e51cba..8139f8ccf89ee9797fa35b54d2c1f09196868983 100644 (file)
@@ -1325,6 +1325,35 @@ SWITCH_DECLARE(uint32_t) switch_core_min_dtmf_duration(uint32_t duration)
        return runtime.min_dtmf_duration;
 }
 
+SWITCH_DECLARE(switch_status_t) switch_core_thread_set_cpu_affinity(int cpu)
+{
+       switch_status_t status = SWITCH_STATUS_FALSE;
+
+       if (cpu > -1) {
+
+#ifdef HAVE_CPU_SET_MACROS
+               cpu_set_t set;
+
+               CPU_ZERO(&set);
+               CPU_SET(cpu, &set);
+
+               if (!sched_setaffinity(0, sizeof(set), &set)) {
+                       status = SWITCH_STATUS_SUCCESS;
+               }
+               
+#else
+#if WIN32
+               if (SetThreadAffinityMask(GetCurrentThread(), (DWORD_PTR) cpu)) {
+                       status = SWITCH_STATUS_SUCCESS;
+               }
+#endif
+#endif
+       }
+
+       return status;
+}
+
+
 static void switch_core_set_serial(void)
 {
        char buf[13] = "";
index fa864526c812fead0dac3b8a1a2188e8729e36be..23670fac93df0d5e3e4799be89be2e21e4cfc907 100644 (file)
@@ -253,16 +253,8 @@ static void *SWITCH_THREAD_FUNC switch_event_dispatch_thread(switch_thread_t *th
 
        EVENT_DISPATCH_QUEUE_RUNNING[my_id] = 1;
        switch_mutex_unlock(EVENT_QUEUE_MUTEX);
-
-#ifdef HAVE_CPU_SET_MACROS
-       {
-               cpu_set_t set;
-               CPU_ZERO(&set);
-               CPU_SET(my_id, &set);
-               sched_setaffinity(0, sizeof(set), &set);                
-       }
-#endif
-
+       
+       switch_core_thread_set_cpu_affinity(my_id);
 
        for (;;) {
                void *pop = NULL;
index 17a0a5067546dd863a3b53b625b16e36bd2945cf..e7256538f36326fb07998df846b7af424fa1810a 100644 (file)
@@ -795,14 +795,9 @@ SWITCH_MODULE_RUNTIME_FUNCTION(softtimer_runtime)
        runtime.profile_timer = switch_new_profile_timer();
        switch_get_system_idle_time(runtime.profile_timer, &runtime.profile_time);
 
-#ifdef HAVE_CPU_SET_MACROS
-       if (runtime.timer_affinity > -1) {
-               cpu_set_t set;
-               CPU_ZERO(&set);
-               CPU_SET(runtime.timer_affinity, &set);
-               sched_setaffinity(0, sizeof(set), &set);
+       if (runtime.timer_affinity > -1) { 
+               switch_core_thread_set_cpu_affinity(runtime.timer_affinity);
        }
-#endif
 
        switch_time_sync();
        time_sync = runtime.time_sync;