WaitHandle.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "il2cpp-config.h"
  2. #include "il2cpp-class-internals.h"
  3. #include "il2cpp-object-internals.h"
  4. #include "vm/WaitHandle.h"
  5. #include "vm/Class.h"
  6. #include "vm/Field.h"
  7. #include "vm/Object.h"
  8. #include "vm/Runtime.h"
  9. namespace il2cpp
  10. {
  11. namespace vm
  12. {
  13. Il2CppWaitHandle* WaitHandle::NewManualResetEvent(bool initialState)
  14. {
  15. static const MethodInfo* constructor = NULL;
  16. if (!constructor)
  17. constructor = Class::GetMethodFromName(il2cpp_defaults.manualresetevent_class, ".ctor", 1);
  18. Il2CppObject* instance = Object::New(il2cpp_defaults.manualresetevent_class);
  19. void* args[1] = { &initialState };
  20. // NOTE: passing NULL here as Mono does, as long as the WaitHandle ctor will never throw an exception.
  21. Runtime::Invoke(constructor, instance, args, NULL);
  22. return reinterpret_cast<Il2CppWaitHandle*>(instance);
  23. }
  24. os::Handle* WaitHandle::GetPlatformHandle(Il2CppWaitHandle* waitHandle)
  25. {
  26. static FieldInfo *s_osHandle;
  27. static FieldInfo *s_safeHandle;
  28. if (!s_osHandle && !s_safeHandle)
  29. {
  30. s_osHandle = vm::Class::GetFieldFromName(il2cpp_defaults.manualresetevent_class, "Handle");
  31. s_safeHandle = vm::Class::GetFieldFromName(il2cpp_defaults.manualresetevent_class, "safeWaitHandle");
  32. }
  33. os::Handle* retval;
  34. if (s_osHandle)
  35. {
  36. intptr_t osHandle;
  37. vm::Field::GetValue((Il2CppObject*)waitHandle, s_osHandle, &osHandle);
  38. retval = reinterpret_cast<os::Handle*>(osHandle);
  39. }
  40. else
  41. {
  42. Il2CppSafeHandle *sh;
  43. vm::Field::GetValue((Il2CppObject*)waitHandle, s_safeHandle, &sh);
  44. retval = static_cast<os::Handle*>(sh->handle);
  45. }
  46. return static_cast<os::Handle*>(retval);
  47. }
  48. } /* namespace vm */
  49. } /* namespace il2cpp */