diff options
| author | 2014-06-01 22:12:54 -0400 | |
|---|---|---|
| committer | 2014-06-01 22:12:54 -0400 | |
| commit | 3fb31fbc57fd1d537db79af898ef26c92b0e0867 (patch) | |
| tree | a4ce54e66ae91c66c0ce55ab32468b3b8ec4d6ab /src | |
| parent | kernel: changed main thread priority to default, updated Kernel::Reschedule t... (diff) | |
| download | yuzu-3fb31fbc57fd1d537db79af898ef26c92b0e0867.tar.gz yuzu-3fb31fbc57fd1d537db79af898ef26c92b0e0867.tar.xz yuzu-3fb31fbc57fd1d537db79af898ef26c92b0e0867.zip | |
svc: added GetThreadPriority and SetThreadPriority, added (incomplete) DuplicateHandle support
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 45 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 6 | ||||
| -rw-r--r-- | src/core/hle/svc.cpp | 29 |
3 files changed, 77 insertions, 3 deletions
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index f2094f7a7..c84fdf91d 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -294,6 +294,51 @@ Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s3 | |||
| 294 | return handle; | 294 | return handle; |
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | /// Get the priority of the thread specified by handle | ||
| 298 | u32 GetThreadPriority(const Handle handle) { | ||
| 299 | Thread* thread = g_object_pool.GetFast<Thread>(handle); | ||
| 300 | _assert_msg_(KERNEL, thread, "called, but thread is NULL!"); | ||
| 301 | return thread->current_priority; | ||
| 302 | } | ||
| 303 | |||
| 304 | /// Set the priority of the thread specified by handle | ||
| 305 | Result SetThreadPriority(Handle handle, s32 priority) { | ||
| 306 | Thread* thread = NULL; | ||
| 307 | if (!handle) { | ||
| 308 | thread = GetCurrentThread(); // TODO(bunnei): Is this correct behavior? | ||
| 309 | } else { | ||
| 310 | thread = g_object_pool.GetFast<Thread>(handle); | ||
| 311 | } | ||
| 312 | _assert_msg_(KERNEL, thread, "called, but thread is NULL!"); | ||
| 313 | |||
| 314 | // If priority is invalid, clamp to valid range | ||
| 315 | if (priority < THREADPRIO_HIGHEST || priority > THREADPRIO_LOWEST) { | ||
| 316 | s32 new_priority = CLAMP(priority, THREADPRIO_HIGHEST, THREADPRIO_LOWEST); | ||
| 317 | WARN_LOG(KERNEL, "invalid priority=0x%08X, clamping to %08X", priority, new_priority); | ||
| 318 | // TODO(bunnei): Clamping to a valid priority is not necessarily correct behavior... Confirm | ||
| 319 | // validity of this | ||
| 320 | priority = new_priority; | ||
| 321 | } | ||
| 322 | |||
| 323 | // Change thread priority | ||
| 324 | s32 old = thread->current_priority; | ||
| 325 | g_thread_ready_queue.remove(old, handle); | ||
| 326 | thread->current_priority = priority; | ||
| 327 | g_thread_ready_queue.prepare(thread->current_priority); | ||
| 328 | |||
| 329 | // Change thread status to "ready" and push to ready queue | ||
| 330 | if (thread->IsRunning()) { | ||
| 331 | thread->status = (thread->status & ~THREADSTATUS_RUNNING) | THREADSTATUS_READY; | ||
| 332 | } | ||
| 333 | if (thread->IsReady()) { | ||
| 334 | g_thread_ready_queue.push_back(thread->current_priority, handle); | ||
| 335 | } | ||
| 336 | |||
| 337 | HLE::EatCycles(450); | ||
| 338 | |||
| 339 | return 0; | ||
| 340 | } | ||
| 341 | |||
| 297 | /// Sets up the primary application thread | 342 | /// Sets up the primary application thread |
| 298 | Handle SetupMainThread(s32 priority, int stack_size) { | 343 | Handle SetupMainThread(s32 priority, int stack_size) { |
| 299 | Handle handle; | 344 | Handle handle; |
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 9628f165d..094c8d43e 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -65,6 +65,12 @@ Handle GetCurrentThreadHandle(); | |||
| 65 | /// Put current thread in a wait state - on WaitSynchronization | 65 | /// Put current thread in a wait state - on WaitSynchronization |
| 66 | void WaitThread_Synchronization(); | 66 | void WaitThread_Synchronization(); |
| 67 | 67 | ||
| 68 | /// Get the priority of the thread specified by handle | ||
| 69 | u32 GetThreadPriority(const Handle handle); | ||
| 70 | |||
| 71 | /// Set the priority of the thread specified by handle | ||
| 72 | Result SetThreadPriority(Handle handle, s32 priority); | ||
| 73 | |||
| 68 | /// Initialize threading | 74 | /// Initialize threading |
| 69 | void ThreadingInit(); | 75 | void ThreadingInit(); |
| 70 | 76 | ||
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 0c2412a65..2384b7936 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp | |||
| @@ -258,6 +258,18 @@ Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 p | |||
| 258 | return 0; | 258 | return 0; |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | /// Gets the priority for the specified thread | ||
| 262 | Result GetThreadPriority(void* _priority, Handle handle) { | ||
| 263 | s32* priority = (s32*)_priority; | ||
| 264 | *priority = Kernel::GetThreadPriority(handle); | ||
| 265 | return 0; | ||
| 266 | } | ||
| 267 | |||
| 268 | /// Sets the priority for the specified thread | ||
| 269 | Result SetThreadPriority(Handle handle, s32 priority) { | ||
| 270 | return Kernel::SetThreadPriority(handle, priority); | ||
| 271 | } | ||
| 272 | |||
| 261 | /// Create a mutex | 273 | /// Create a mutex |
| 262 | Result CreateMutex(void* _mutex, u32 initial_locked) { | 274 | Result CreateMutex(void* _mutex, u32 initial_locked) { |
| 263 | Handle* mutex = (Handle*)_mutex; | 275 | Handle* mutex = (Handle*)_mutex; |
| @@ -299,7 +311,18 @@ Result CreateEvent(void* _event, u32 reset_type) { | |||
| 299 | /// Duplicates a kernel handle | 311 | /// Duplicates a kernel handle |
| 300 | Result DuplicateHandle(void* _out, Handle handle) { | 312 | Result DuplicateHandle(void* _out, Handle handle) { |
| 301 | Handle* out = (Handle*)_out; | 313 | Handle* out = (Handle*)_out; |
| 302 | ERROR_LOG(SVC, "(UNIMPLEMENTED) called handle=0x%08X", handle); | 314 | ERROR_LOG(SVC, "called handle=0x%08X", handle); |
| 315 | |||
| 316 | // Translate kernel handles -> real handles | ||
| 317 | if (handle == Kernel::CurrentThread) { | ||
| 318 | handle = Kernel::GetCurrentThreadHandle(); | ||
| 319 | } | ||
| 320 | _assert_msg_(KERNEL, (handle != Kernel::CurrentProcess), | ||
| 321 | "(UNIMPLEMENTED) process handle duplication!"); | ||
| 322 | |||
| 323 | // TODO(bunnei): FixMe - This is a hack to return the handle that we were asked to duplicate. | ||
| 324 | *out = handle; | ||
| 325 | |||
| 303 | return 0; | 326 | return 0; |
| 304 | } | 327 | } |
| 305 | 328 | ||
| @@ -327,8 +350,8 @@ const HLE::FunctionDef SVC_Table[] = { | |||
| 327 | {0x08, WrapI_UUUUU<CreateThread>, "CreateThread"}, | 350 | {0x08, WrapI_UUUUU<CreateThread>, "CreateThread"}, |
| 328 | {0x09, NULL, "ExitThread"}, | 351 | {0x09, NULL, "ExitThread"}, |
| 329 | {0x0A, WrapV_S64<SleepThread>, "SleepThread"}, | 352 | {0x0A, WrapV_S64<SleepThread>, "SleepThread"}, |
| 330 | {0x0B, NULL, "GetThreadPriority"}, | 353 | {0x0B, WrapI_VU<GetThreadPriority>, "GetThreadPriority"}, |
| 331 | {0x0C, NULL, "SetThreadPriority"}, | 354 | {0x0C, WrapI_UI<SetThreadPriority>, "SetThreadPriority"}, |
| 332 | {0x0D, NULL, "GetThreadAffinityMask"}, | 355 | {0x0D, NULL, "GetThreadAffinityMask"}, |
| 333 | {0x0E, NULL, "SetThreadAffinityMask"}, | 356 | {0x0E, NULL, "SetThreadAffinityMask"}, |
| 334 | {0x0F, NULL, "GetThreadIdealProcessor"}, | 357 | {0x0F, NULL, "GetThreadIdealProcessor"}, |