thread.h 3.6 KB

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