thread.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright 2014 Citra Emulator Project / PPSSPP Project
  2. // Licensed under GPLv2
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include "common/common_types.h"
  6. #include "core/hle/kernel/kernel.h"
  7. #include "core/hle/result.h"
  8. enum ThreadPriority {
  9. THREADPRIO_HIGHEST = 0, ///< Highest thread priority
  10. THREADPRIO_DEFAULT = 16, ///< Default thread priority for userland apps
  11. THREADPRIO_LOW = 31, ///< Low range of thread priority for userland apps
  12. THREADPRIO_LOWEST = 63, ///< Thread priority max checked by svcCreateThread
  13. };
  14. enum ThreadProcessorId {
  15. THREADPROCESSORID_0 = 0xFFFFFFFE, ///< Enables core appcode
  16. THREADPROCESSORID_1 = 0xFFFFFFFD, ///< Enables core syscore
  17. THREADPROCESSORID_ALL = 0xFFFFFFFC, ///< Enables both cores
  18. };
  19. enum ThreadStatus {
  20. THREADSTATUS_RUNNING = 1,
  21. THREADSTATUS_READY = 2,
  22. THREADSTATUS_WAIT = 4,
  23. THREADSTATUS_SUSPEND = 8,
  24. THREADSTATUS_DORMANT = 16,
  25. THREADSTATUS_DEAD = 32,
  26. THREADSTATUS_WAITSUSPEND = THREADSTATUS_WAIT | THREADSTATUS_SUSPEND
  27. };
  28. enum WaitType {
  29. WAITTYPE_NONE,
  30. WAITTYPE_SLEEP,
  31. WAITTYPE_SEMA,
  32. WAITTYPE_EVENT,
  33. WAITTYPE_THREADEND,
  34. WAITTYPE_VBLANK,
  35. WAITTYPE_MUTEX,
  36. WAITTYPE_SYNCH,
  37. WAITTYPE_ARB,
  38. };
  39. namespace Kernel {
  40. /// Creates a new thread - wrapper for external user
  41. Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s32 processor_id,
  42. u32 stack_top, int stack_size=Kernel::DEFAULT_STACK_SIZE);
  43. /// Sets up the primary application thread
  44. Handle SetupMainThread(s32 priority, int stack_size=Kernel::DEFAULT_STACK_SIZE);
  45. /// Reschedules to the next available thread (call after current thread is suspended)
  46. void Reschedule();
  47. /// Stops the current thread
  48. ResultCode StopThread(Handle thread, const char* reason);
  49. /// Resumes a thread from waiting by marking it as "ready"
  50. void ResumeThreadFromWait(Handle handle);
  51. /// Arbitrate the highest priority thread that is waiting
  52. Handle ArbitrateHighestPriorityThread(u32 arbiter, u32 address);
  53. /// Arbitrate all threads currently waiting...
  54. void ArbitrateAllThreads(u32 arbiter, u32 address);
  55. /// Gets the current thread handle
  56. Handle GetCurrentThreadHandle();
  57. /**
  58. * Puts the current thread in the wait state for the given type
  59. * @param wait_type Type of wait
  60. * @param wait_handle Handle of Kernel object that we are waiting on, defaults to current thread
  61. */
  62. void WaitCurrentThread(WaitType wait_type, Handle wait_handle=GetCurrentThreadHandle());
  63. /// Put current thread in a wait state - on WaitSynchronization
  64. void WaitThread_Synchronization();
  65. /// Get the priority of the thread specified by handle
  66. ResultVal<u32> GetThreadPriority(const Handle handle);
  67. /// Set the priority of the thread specified by handle
  68. ResultCode SetThreadPriority(Handle handle, s32 priority);
  69. /// Initialize threading
  70. void ThreadingInit();
  71. /// Shutdown threading
  72. void ThreadingShutdown();
  73. } // namespace