WriteBarrierMacros.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #pragma once
  6. //
  7. // WriteBarrier Macros are weird because of "compat"
  8. // In general, write barriers are used only on non-Win32 builds
  9. // However, for perf, some classes are also allocated in Write-Barrier memory, even on Windows
  10. // Those classes can force WriteBarrier types to always be generated for their definitions
  11. //
  12. // Usage:
  13. // In general, don't need to use anything, just use the macros to annotate your fields
  14. //
  15. //
  16. #define FieldWithBarrier(type, ...) \
  17. WriteBarrierFieldTypeTraits<type, ##__VA_ARGS__>::Type
  18. #if GLOBAL_ENABLE_WRITE_BARRIER
  19. #define Field(type, ...) \
  20. typename FieldWithBarrier(type, ##__VA_ARGS__)
  21. #define FieldNoBarrier(type) \
  22. typename WriteBarrierFieldTypeTraits<type, _no_write_barrier_policy, _no_write_barrier_policy>::Type
  23. #define NO_WRITE_BARRIER_TAG_TYPE(arg) arg, _no_write_barrier_tag
  24. #define NO_WRITE_BARRIER_TAG(arg) arg, _no_write_barrier_tag()
  25. #else
  26. #define Field(type, ...) type
  27. #define FieldNoBarrier(type) type
  28. #define NO_WRITE_BARRIER_TAG_TYPE(arg) arg
  29. #define NO_WRITE_BARRIER_TAG(arg) arg
  30. #endif
  31. // use with FieldWithBarrier structs
  32. #define FORCE_NO_WRITE_BARRIER_TAG(arg) arg, _no_write_barrier_tag()