ScopedThreadAttacher.cpp 744 B

12345678910111213141516171819202122232425
  1. #include "il2cpp-config.h"
  2. #include "vm/Thread.h"
  3. #include "vm/Domain.h"
  4. #include "vm/Runtime.h"
  5. #include "ScopedThreadAttacher.h"
  6. il2cpp::vm::ScopedThreadAttacher::ScopedThreadAttacher()
  7. : m_AttachedThread(NULL)
  8. {
  9. #if IL2CPP_TINY
  10. if (il2cpp::vm::Thread::Current() != il2cpp::vm::Thread::Main())
  11. il2cpp::vm::Runtime::FailFast("Managed code must be compiled with Burst to execute on a non-main thread.");
  12. #else
  13. if (il2cpp::vm::Thread::Current() == NULL)
  14. m_AttachedThread = il2cpp::vm::Thread::Attach(il2cpp::vm::Domain::GetRoot());
  15. #endif
  16. }
  17. il2cpp::vm::ScopedThreadAttacher::~ScopedThreadAttacher()
  18. {
  19. #if !IL2CPP_TINY
  20. if (m_AttachedThread != NULL)
  21. il2cpp::vm::Thread::Detach(m_AttachedThread);
  22. #endif
  23. }