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:
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;
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] = "";
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;
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;