From 56d040d3cc6c66ac44028fb8e0c4c6cd3a6c56af Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Thu, 7 Dec 2000 23:15:41 +0000 Subject: [PATCH] be able to set thread priority --- panda/src/audio/audio_manager.cxx | 19 ++++++++++++++++++- panda/src/audio/config_audio.cxx | 12 ++++++++++++ panda/src/audio/config_audio.h | 1 + 3 files changed, 31 insertions(+), 1 deletion(-) diff --git a/panda/src/audio/audio_manager.cxx b/panda/src/audio/audio_manager.cxx index 9200c5567a..f108e6b832 100644 --- a/panda/src/audio/audio_manager.cxx +++ b/panda/src/audio/audio_manager.cxx @@ -164,7 +164,24 @@ void AudioManager::ns_spawn_update(void) { if (_quit == (bool*)0L) _quit = new bool(false); *_quit = false; - _spawned = thread::create(spawned_update, _quit, thread::PRIORITY_LOW); + thread::priority_t pri; + switch (audio_thread_priority) { + case 0: + pri = thread::PRIORITY_LOW; + break; + case 1: + pri = thread::PRIORITY_NORMAL; + break; + case 2: + pri = thread::PRIORITY_HIGH; + break; + default: + audio_cat->error() << "audio-thread-priority set to something other " + << "then low, normal, or high" << endl; + audio_thread_priority = 1; + pri = thread::PRIORITY_NORMAL; + } + _spawned = thread::create(spawned_update, _quit, pri); } else { audio_cat->error() << "tried to spawn 2 update threads" << endl; } diff --git a/panda/src/audio/config_audio.cxx b/panda/src/audio/config_audio.cxx index 86540898d1..077cdf1bbc 100644 --- a/panda/src/audio/config_audio.cxx +++ b/panda/src/audio/config_audio.cxx @@ -46,6 +46,18 @@ ConfigureFn(config_audio) { audio_device = new string(config_audio.GetString("audio-device", "/dev/dsp")); + + string stmp = config_audio.GetString("audio-thread-priority", "NORMAL"); + for (string::iterator q=stmp.begin(); q!=stmp.end(); ++q) + (*q) = toupper(*q); + if (stmp == "LOW") + audio_thread_priority = 0; + else if (stmp == "NORMAL") + audio_thread_priority = 1; + else if (stmp == "HIGH") + audio_thread_priority = 2; + else + audio_thread_priority = -1; } void audio_load_loaders(void) { diff --git a/panda/src/audio/config_audio.h b/panda/src/audio/config_audio.h index 9ab17fec63..a92929c409 100644 --- a/panda/src/audio/config_audio.h +++ b/panda/src/audio/config_audio.h @@ -20,6 +20,7 @@ extern EXPCL_PANDA int audio_buffer_size; extern EXPCL_PANDA string* audio_device; extern EXPCL_PANDA int audio_auto_update_delay; extern EXPCL_PANDA bool audio_is_active; +extern EXPCL_PANDA int audio_thread_priority; extern EXPCL_PANDA void audio_load_loaders(void);