Thread.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2008 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <thread>
  5. #ifndef _WIN32
  6. #include <tuple>
  7. #endif
  8. // Don't include Common.h here as it will break LogManager
  9. #include "Common/CommonTypes.h"
  10. // This may not be defined outside _WIN32
  11. #ifndef _WIN32
  12. #ifndef INFINITE
  13. #define INFINITE 0xffffffff
  14. #endif
  15. #endif
  16. namespace Common
  17. {
  18. int CurrentThreadId();
  19. void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask);
  20. void SetCurrentThreadAffinity(u32 mask);
  21. void SleepCurrentThread(int ms);
  22. void SwitchCurrentThread(); // On Linux, this is equal to sleep 1ms
  23. // Use this function during a spin-wait to make the current thread
  24. // relax while another thread is working. This may be more efficient
  25. // than using events because event functions use kernel calls.
  26. inline void YieldCPU()
  27. {
  28. std::this_thread::yield();
  29. }
  30. void SetCurrentThreadName(const char* name);
  31. #ifndef _WIN32
  32. // Returns the lowest address of the stack and the size of the stack
  33. std::tuple<void*, size_t> GetCurrentThreadStack();
  34. #endif
  35. } // namespace Common