storage_file_lock.h 725 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #pragma once
  8. #include "base/basic_types.h"
  9. #include <QtCore/QFile>
  10. namespace Storage {
  11. class FileLock {
  12. public:
  13. FileLock();
  14. bool lock(QFile &file, QIODevice::OpenMode mode);
  15. void unlock();
  16. static constexpr auto kSkipBytes = size_type(4);
  17. ~FileLock();
  18. private:
  19. class Lock;
  20. struct Descriptor;
  21. struct LockingPid;
  22. static constexpr auto kLockOffset = index_type(0);
  23. static constexpr auto kLockLimit = kSkipBytes;
  24. std::unique_ptr<Lock> _lock;
  25. };
  26. } // namespace Storage