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.

46 lines
813B

  1. #pragma once
  2. #include <atomic>
  3. #include <memory>
  4. class MidiLock;
  5. using MidiLockPtr = std::shared_ptr<MidiLock>;
  6. class MidiLock
  7. {
  8. public:
  9. MidiLock();
  10. MidiLock(const MidiLock&) = delete;
  11. const MidiLock& operator = (const MidiLock&) = delete;
  12. static MidiLockPtr make();
  13. void editorLock();
  14. void editorUnlock();
  15. bool playerTryLock();
  16. void playerUnlock();
  17. bool locked() const;
  18. /**
  19. * Returns true is an editor lock has occurred since last query.
  20. * Will clear flag after calling
  21. */
  22. bool dataModelDirty();
  23. private:
  24. std::atomic<bool> theLock;
  25. std::atomic<int> editorLockLevel;
  26. std::atomic<bool> editorDidLock;
  27. bool tryLock();
  28. };
  29. class MidiLocker
  30. {
  31. public:
  32. MidiLocker(MidiLockPtr);
  33. ~MidiLocker();
  34. private:
  35. MidiLockPtr lock;
  36. };