thread.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. };
  37. namespace Kernel {
  38. /// Creates a new thread - wrapper for external user
  39. Handle CreateThread(const char* name, u32 entry_point, s32 priority, u32 arg, s32 processor_id,
  40. u32 stack_top, int stack_size=Kernel::DEFAULT_STACK_SIZE);
  41. /// Sets up the primary application thread
  42. Handle SetupMainThread(s32 priority, int stack_size=Kernel::DEFAULT_STACK_SIZE);
  43. /// Reschedules to the next available thread (call after current thread is suspended)
  44. void Reschedule();
  45. /// Stops the current thread
  46. void StopThread(Handle thread, const char* reason);
  47. /// Resumes a thread from waiting by marking it as "ready"
  48. void ResumeThreadFromWait(Handle handle);
  49. /// Gets the current thread handle
  50. Handle GetCurrentThreadHandle();
  51. /// Puts the current thread in the wait state for the given type
  52. void WaitCurrentThread(WaitType wait_type, Handle wait_handle=GetCurrentThreadHandle());
  53. /// Put current thread in a wait state - on WaitSynchronization
  54. void WaitThread_Synchronization();
  55. /// Get the priority of the thread specified by handle
  56. u32 GetThreadPriority(const Handle handle);
  57. /// Set the priority of the thread specified by handle
  58. Result SetThreadPriority(Handle handle, s32 priority);
  59. /// Initialize threading
  60. void ThreadingInit();
  61. /// Shutdown threading
  62. void ThreadingShutdown();
  63. } // namespace