cmFileLockPool.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 "cmStandardIncludes.h"
  13. class cmFileLockResult;
  14. class cmFileLock;
  15. class cmFileLockPool
  16. {
  17. public:
  18. cmFileLockPool();
  19. ~cmFileLockPool();
  20. //@{
  21. /**
  22. * @brief Function scope control.
  23. */
  24. void PushFunctionScope();
  25. void PopFunctionScope();
  26. //@}
  27. //@{
  28. /**
  29. * @brief File scope control.
  30. */
  31. void PushFileScope();
  32. void PopFileScope();
  33. //@}
  34. //@{
  35. /**
  36. * @brief Lock the file in given scope.
  37. * @param timeoutSec Lock timeout. If -1 try until success or fatal error.
  38. */
  39. cmFileLockResult LockFunctionScope(
  40. const std::string& filename, unsigned long timeoutSec
  41. );
  42. cmFileLockResult LockFileScope(
  43. const std::string& filename, unsigned long timeoutSec
  44. );
  45. cmFileLockResult LockProcessScope(
  46. const std::string& filename, unsigned long timeoutSec
  47. );
  48. //@}
  49. /**
  50. * @brief Unlock the file explicitly.
  51. */
  52. cmFileLockResult Release(const std::string& filename);
  53. private:
  54. cmFileLockPool(const cmFileLockPool&);
  55. cmFileLockPool& operator=(const cmFileLockPool&);
  56. bool IsAlreadyLocked(const std::string& filename) const;
  57. class ScopePool
  58. {
  59. public:
  60. ScopePool();
  61. ~ScopePool();
  62. cmFileLockResult Lock(
  63. const std::string& filename, unsigned long timeoutSec
  64. );
  65. cmFileLockResult Release(const std::string& filename);
  66. bool IsAlreadyLocked(const std::string& filename) const;
  67. private:
  68. ScopePool(const ScopePool&);
  69. ScopePool& operator=(const ScopePool&);
  70. typedef std::list<cmFileLock*> List;
  71. typedef List::iterator It;
  72. typedef List::const_iterator CIt;
  73. List Locks;
  74. };
  75. typedef std::list<ScopePool*> List;
  76. typedef List::iterator It;
  77. typedef List::const_iterator CIt;
  78. List FunctionScopes;
  79. List FileScopes;
  80. ScopePool ProcessScope;
  81. };
  82. #endif // cmFileLockPool_h