cmFileLockPool.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2014 Ruslan Baratov
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef cmFileLockPool_h
  11. #define cmFileLockPool_h
  12. #include <cmConfigure.h> // IWYU pragma: keep
  13. #include <list>
  14. #include <string>
  15. class cmFileLock;
  16. class cmFileLockResult;
  17. class cmFileLockPool
  18. {
  19. public:
  20. cmFileLockPool();
  21. ~cmFileLockPool();
  22. //@{
  23. /**
  24. * @brief Function scope control.
  25. */
  26. void PushFunctionScope();
  27. void PopFunctionScope();
  28. //@}
  29. //@{
  30. /**
  31. * @brief File scope control.
  32. */
  33. void PushFileScope();
  34. void PopFileScope();
  35. //@}
  36. //@{
  37. /**
  38. * @brief Lock the file in given scope.
  39. * @param timeoutSec Lock timeout. If -1 try until success or fatal error.
  40. */
  41. cmFileLockResult LockFunctionScope(const std::string& filename,
  42. unsigned long timeoutSec);
  43. cmFileLockResult LockFileScope(const std::string& filename,
  44. unsigned long timeoutSec);
  45. cmFileLockResult LockProcessScope(const std::string& filename,
  46. unsigned long timeoutSec);
  47. //@}
  48. /**
  49. * @brief Unlock the file explicitly.
  50. */
  51. cmFileLockResult Release(const std::string& filename);
  52. private:
  53. cmFileLockPool(const cmFileLockPool&);
  54. cmFileLockPool& operator=(const cmFileLockPool&);
  55. bool IsAlreadyLocked(const std::string& filename) const;
  56. class ScopePool
  57. {
  58. public:
  59. ScopePool();
  60. ~ScopePool();
  61. cmFileLockResult Lock(const std::string& filename,
  62. unsigned long timeoutSec);
  63. cmFileLockResult Release(const std::string& filename);
  64. bool IsAlreadyLocked(const std::string& filename) const;
  65. private:
  66. ScopePool(const ScopePool&);
  67. ScopePool& operator=(const ScopePool&);
  68. typedef std::list<cmFileLock*> List;
  69. typedef List::iterator It;
  70. typedef List::const_iterator CIt;
  71. List Locks;
  72. };
  73. typedef std::list<ScopePool*> List;
  74. typedef List::iterator It;
  75. typedef List::const_iterator CIt;
  76. List FunctionScopes;
  77. List FileScopes;
  78. ScopePool ProcessScope;
  79. };
  80. #endif // cmFileLockPool_h