thread.h 2.9 KB

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