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.

55 lines
873B

  1. #include <context.hpp>
  2. #include <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. namespace rack {
  9. Context::~Context() {
  10. // Deleting NULL is safe in C++.
  11. // Set pointers to NULL so other objects will segfault when attempting to access them
  12. delete window;
  13. window = NULL;
  14. delete patch;
  15. patch = NULL;
  16. delete scene;
  17. scene = NULL;
  18. delete event;
  19. event = NULL;
  20. delete history;
  21. history = NULL;
  22. delete engine;
  23. engine = NULL;
  24. }
  25. static thread_local Context* threadContext = NULL;
  26. Context* contextGet() {
  27. assert(threadContext);
  28. return threadContext;
  29. }
  30. // Apple's clang incorrectly compiles this function when -O2 or higher is enabled.
  31. #ifdef ARCH_MAC
  32. __attribute__((optnone))
  33. #endif
  34. void contextSet(Context* context) {
  35. threadContext = context;
  36. }
  37. } // namespace rack