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.

72 lines
1.4KB

  1. #include <context.hpp>
  2. #include <window/Window.hpp>
  3. #include <patch.hpp>
  4. #include <engine/Engine.hpp>
  5. #include <app/Scene.hpp>
  6. #include <history.hpp>
  7. #include <settings.hpp>
  8. #ifdef NDEBUG
  9. # undef DEBUG
  10. #endif
  11. #include "DistrhoUtils.hpp"
  12. /**
  13. * This file is an edited version of VCVRack's context.cpp
  14. * Copyright (C) 2016-2021 VCV.
  15. *
  16. * This program is free software: you can redistribute it and/or
  17. * modify it under the terms of the GNU General Public License as
  18. * published by the Free Software Foundation; either version 3 of
  19. * the License, or (at your option) any later version.
  20. */
  21. namespace rack {
  22. Context::~Context() {
  23. // Deleting NULL is safe in C++.
  24. // Set pointers to NULL so other objects will segfault when attempting to access them
  25. delete window;
  26. window = NULL;
  27. delete patch;
  28. patch = NULL;
  29. delete scene;
  30. scene = NULL;
  31. delete event;
  32. event = NULL;
  33. delete history;
  34. history = NULL;
  35. delete engine;
  36. engine = NULL;
  37. }
  38. static thread_local Context* threadContext = nullptr;
  39. Context* contextGet() {
  40. DISTRHO_SAFE_ASSERT(threadContext != nullptr);
  41. return threadContext;
  42. }
  43. // Apple's clang incorrectly compiles this function when -O2 or higher is enabled.
  44. #ifdef ARCH_MAC
  45. __attribute__((optnone))
  46. #endif
  47. void contextSet(Context* const context) {
  48. // DISTRHO_SAFE_ASSERT(threadContext == nullptr);
  49. threadContext = context;
  50. }
  51. } // namespace rack