锁优化
This commit is contained in:
+1
-56
@@ -14,62 +14,7 @@
|
||||
#include <QtWidgets>
|
||||
#include <QtWidgetsDepends>
|
||||
#include <functional>
|
||||
|
||||
#include "psc_global_include/Singleton.hpp"
|
||||
|
||||
// template <typename Derived>
|
||||
// class Singleton {
|
||||
// public:
|
||||
// static Derived* instance() {
|
||||
// Derived* temp = instance_.load(std::memory_order_acquire);
|
||||
// if (temp == nullptr) {
|
||||
// std::lock_guard<std::mutex> lock(mutex_);
|
||||
// temp = instance_.load(std::memory_order_relaxed);
|
||||
// if (temp == nullptr) {
|
||||
// temp = new Derived;
|
||||
// instance_.store(temp, std::memory_order_release);
|
||||
// }
|
||||
// }
|
||||
// return temp;
|
||||
// }
|
||||
// Singleton(const Singleton&) = delete;
|
||||
// Singleton& operator=(const Singleton&) = delete;
|
||||
// protected:
|
||||
// Singleton() = default;
|
||||
// ~Singleton() = default;
|
||||
// private:
|
||||
// static std::atomic<Derived*> instance_;
|
||||
// static std::mutex mutex_;
|
||||
// };
|
||||
// template<typename Derived>
|
||||
// std::atomic<Derived*> Singleton<Derived>::instance_(nullptr);
|
||||
// template<typename Derived>
|
||||
// std::mutex Singleton<Derived>::mutex_;
|
||||
|
||||
//template<typename T>
|
||||
//class Singleton {
|
||||
//public:
|
||||
// static T *instance() {
|
||||
// if(!mInstance) {
|
||||
// mInstance = new T();
|
||||
// }
|
||||
// return mInstance;
|
||||
// }
|
||||
// virtual ~Singleton() = default;
|
||||
// Singleton(T &&) = delete;
|
||||
// Singleton(const T &) = delete;
|
||||
// void operator=(const T &) = delete;
|
||||
//protected:
|
||||
// Singleton() = default;
|
||||
// static T* mInstance;
|
||||
//};
|
||||
//template<typename T> T* Singleton<T>::mInstance = nullptr;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class Global : public Psc::Singleton<Global> {
|
||||
public:
|
||||
explicit Global();
|
||||
@@ -101,4 +46,4 @@ QPushButton *createClickButton(const QString &text, int fontSize, const std::fun
|
||||
|
||||
QPushButton* createNormal(const QString& text, int fontSize, const std::function<void(void)>& mFunc = nullptr);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user