Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

WriteBarrier.h 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #pragma once
  2. #include <type_traits>
  3. struct Il2CppObject;
  4. namespace il2cpp
  5. {
  6. namespace gc
  7. {
  8. class WriteBarrier
  9. {
  10. public:
  11. static void GenericStore(void** ptr, void* value);
  12. template<typename TPtr, typename TValue>
  13. static void GenericStore(TPtr** ptr, TValue* value)
  14. {
  15. static_assert((std::is_assignable<TPtr*&, TValue*>::value), "Pointers types are not assignment compatible");
  16. GenericStore((void**)ptr, (void*)value);
  17. }
  18. template<typename TPtr>
  19. static void GenericStoreNull(TPtr** ptr)
  20. {
  21. *ptr = NULL;
  22. }
  23. };
  24. } /* gc */
  25. } /* il2cpp */
  26. #define IL2CPP_OBJECT_SETREF(obj, fieldname, value) do {\
  27. il2cpp::gc::WriteBarrier::GenericStore(&(obj)->fieldname, (value));\
  28. } while (0)
  29. /* This should be used if 's' can reside on the heap */
  30. #define IL2CPP_STRUCT_SETREF(s, fieldname, value) do {\
  31. il2cpp::gc::WriteBarrier::GenericStore(&(s)->fieldname, (value));\
  32. } while (0)
  33. #define IL2CPP_OBJECT_SETREF_NULL(obj, fieldname) do {\
  34. il2cpp::gc::WriteBarrier::GenericStoreNull(&(obj)->fieldname);\
  35. } while (0)