diff options
| author | 2020-04-05 09:48:53 -0400 | |
|---|---|---|
| committer | 2020-06-27 11:36:09 -0400 | |
| commit | 528b19a84287167d7699465e495b196d216b99db (patch) | |
| tree | c3ac61644c1a11fd1cf5ceeb70d1c9f5d4a00aa3 /src/common/thread.cpp | |
| parent | Dynarmic Interface: don't clear cache if JIT has not been created. (diff) | |
| download | yuzu-528b19a84287167d7699465e495b196d216b99db.tar.gz yuzu-528b19a84287167d7699465e495b196d216b99db.tar.xz yuzu-528b19a84287167d7699465e495b196d216b99db.zip | |
General: Tune the priority of main emulation threads so they have higher priority than less important helper threads.
Diffstat (limited to 'src/common/thread.cpp')
| -rw-r--r-- | src/common/thread.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/common/thread.cpp b/src/common/thread.cpp index c9684aed9..33c8437f5 100644 --- a/src/common/thread.cpp +++ b/src/common/thread.cpp | |||
| @@ -25,6 +25,52 @@ | |||
| 25 | 25 | ||
| 26 | namespace Common { | 26 | namespace Common { |
| 27 | 27 | ||
| 28 | #ifdef _WIN32 | ||
| 29 | |||
| 30 | void SetCurrentThreadPriority(ThreadPriority new_priority) { | ||
| 31 | auto handle = GetCurrentThread(); | ||
| 32 | int windows_priority = 0; | ||
| 33 | switch (new_priority) { | ||
| 34 | case ThreadPriority::Low: | ||
| 35 | windows_priority = THREAD_PRIORITY_BELOW_NORMAL; | ||
| 36 | break; | ||
| 37 | case ThreadPriority::Normal: | ||
| 38 | windows_priority = THREAD_PRIORITY_NORMAL; | ||
| 39 | break; | ||
| 40 | case ThreadPriority::High: | ||
| 41 | windows_priority = THREAD_PRIORITY_ABOVE_NORMAL; | ||
| 42 | break; | ||
| 43 | case ThreadPriority::VeryHigh: | ||
| 44 | windows_priority = THREAD_PRIORITY_HIGHEST; | ||
| 45 | break; | ||
| 46 | default: | ||
| 47 | windows_priority = THREAD_PRIORITY_NORMAL; | ||
| 48 | break; | ||
| 49 | } | ||
| 50 | SetThreadPriority(handle, windows_priority); | ||
| 51 | } | ||
| 52 | |||
| 53 | #else | ||
| 54 | |||
| 55 | void SetCurrentThreadPriority(ThreadPriority new_priority) { | ||
| 56 | pthread_t this_thread = pthread_self(); | ||
| 57 | |||
| 58 | s32 max_prio = sched_get_priority_max(SCHED_OTHER); | ||
| 59 | s32 min_prio = sched_get_priority_min(SCHED_OTHER); | ||
| 60 | u32 level = static_cast<u32>(new_priority) + 1; | ||
| 61 | |||
| 62 | struct sched_param params; | ||
| 63 | if (max_prio > min_prio) { | ||
| 64 | params.sched_priority = min_prio + ((max_prio - min_prio) * level) / 4; | ||
| 65 | } else { | ||
| 66 | params.sched_priority = min_prio - ((min_prio - max_prio) * level) / 4; | ||
| 67 | } | ||
| 68 | |||
| 69 | pthread_setschedparam(this_thread, SCHED_OTHER, ¶ms); | ||
| 70 | } | ||
| 71 | |||
| 72 | #endif | ||
| 73 | |||
| 28 | #ifdef _MSC_VER | 74 | #ifdef _MSC_VER |
| 29 | 75 | ||
| 30 | // Sets the debugger-visible name of the current thread. | 76 | // Sets the debugger-visible name of the current thread. |