1
0

cmFileLockPool.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef cmFileLockPool_h
  4. #define cmFileLockPool_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <string>
  7. #include <vector>
  8. class cmFileLock;
  9. class cmFileLockResult;
  10. class cmFileLockPool
  11. {
  12. public:
  13. cmFileLockPool();
  14. ~cmFileLockPool();
  15. cmFileLockPool(cmFileLockPool const&) = delete;
  16. cmFileLockPool& operator=(cmFileLockPool const&) = delete;
  17. //@{
  18. /**
  19. * @brief Function scope control.
  20. */
  21. void PushFunctionScope();
  22. void PopFunctionScope();
  23. //@}
  24. //@{
  25. /**
  26. * @brief File scope control.
  27. */
  28. void PushFileScope();
  29. void PopFileScope();
  30. //@}
  31. //@{
  32. /**
  33. * @brief Lock the file in given scope.
  34. * @param timeoutSec Lock timeout. If -1 try until success or fatal error.
  35. */
  36. cmFileLockResult LockFunctionScope(const std::string& filename,
  37. unsigned long timeoutSec);
  38. cmFileLockResult LockFileScope(const std::string& filename,
  39. unsigned long timeoutSec);
  40. cmFileLockResult LockProcessScope(const std::string& filename,
  41. unsigned long timeoutSec);
  42. //@}
  43. /**
  44. * @brief Unlock the file explicitly.
  45. */
  46. cmFileLockResult Release(const std::string& filename);
  47. private:
  48. bool IsAlreadyLocked(const std::string& filename) const;
  49. class ScopePool
  50. {
  51. public:
  52. ScopePool();
  53. ~ScopePool();
  54. ScopePool(ScopePool const&) = delete;
  55. ScopePool& operator=(ScopePool const&) = delete;
  56. cmFileLockResult Lock(const std::string& filename,
  57. unsigned long timeoutSec);
  58. cmFileLockResult Release(const std::string& filename);
  59. bool IsAlreadyLocked(const std::string& filename) const;
  60. private:
  61. typedef std::vector<cmFileLock*> List;
  62. typedef List::iterator It;
  63. typedef List::const_iterator CIt;
  64. List Locks;
  65. };
  66. typedef std::vector<ScopePool*> List;
  67. typedef List::iterator It;
  68. typedef List::const_iterator CIt;
  69. List FunctionScopes;
  70. List FileScopes;
  71. ScopePool ProcessScope;
  72. };
  73. #endif // cmFileLockPool_h