diff options
author | Kevin Funk <kfunk@kde.org> | 2017-10-22 11:30:49 +0100 |
---|---|---|
committer | Sergio Martins <iamsergio@gmail.com> | 2017-10-22 11:32:16 +0100 |
commit | 27114916412ad20321cc63af5651a301455bf79a (patch) | |
tree | 39d37fc97fb54e572e33c34eacf060a9ac3c7f69 /src/checkmanager.h | |
parent | ec9ec84e7fd73f5a4753973660ad4f301eaa8c0e (diff) |
Protect CheckManager with mutex
Needed in case Clazy is used as a plugin inside libclang. There, we
might have multiple threads accessing CheckManager concurrently.
Diffstat (limited to 'src/checkmanager.h')
-rw-r--r-- | src/checkmanager.h | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/checkmanager.h b/src/checkmanager.h index 63e00a7a..efedd26d 100644 --- a/src/checkmanager.h +++ b/src/checkmanager.h @@ -77,8 +77,15 @@ inline bool checkLessThanByLevel(const RegisteredCheck &c1, const RegisteredChec class CLAZYLIB_EXPORT CheckManager { public: + /** + * @note You must hold the CheckManager lock when operating on the instance + * + * @sa lock() + */ static CheckManager *instance(); + static std::mutex &lock() { return m_lock; } + int registerCheck(const std::string &name, const std::string &className, CheckLevel level, const FactoryFunction &, RegisteredCheck::Options = RegisteredCheck::Option_None); int registerFixIt(int id, const std::string &fititName, const std::string &checkName); @@ -105,6 +112,7 @@ public: private: CheckManager(); + static std::mutex m_lock; bool checkExists(const std::string &name) const; RegisteredCheck::List checksForLevel(int level) const; |