Browse Source

be able to set thread priority

Cary Sandvig 25 years ago
parent
commit
56d040d3cc

+ 18 - 1
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;
   }

+ 12 - 0
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) {

+ 1 - 0
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);