cmFileLockPool.h 2.4 KB

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