reg_zone.cpp 780 B

123456789101112131415161718192021222324252627282930313233
  1. #include <util/system/compiler.h>
  2. extern "C" void je_zone_register();
  3. static volatile bool initialized = false;
  4. namespace {
  5. struct TInit {
  6. inline TInit() {
  7. if (!initialized) {
  8. je_zone_register();
  9. initialized = true;
  10. }
  11. }
  12. };
  13. void zone_register() {
  14. static TInit init;
  15. }
  16. }
  17. extern "C" {
  18. void je_assure_zone_register() {
  19. if (Y_LIKELY(initialized)) {
  20. return;
  21. }
  22. // Even if we have read false "initialized", real init will be syncronized once by
  23. // Meyers singleton in <anonymous>::register_zone(). We could do a few
  24. // redundant "initialized" and singleton creation checks, but no more than that.
  25. zone_register();
  26. }
  27. }