123456789101112131415161718192021222324252627 |
- #pragma once
- #include <thread>
- #include <mutex>
- template <class Type>
- class lockFunc {
- public:
- template<class Func, class ... Args>
- int lock_exe(Func func, Args&&... args) {
- lock.lock();
- bool ret = ((Type* )this->*func)(args...);
- lock.unlock();
- return ret;
- }
- template<class Func, class ... Args>
- int lock_exe(Func func, Type* p, Args&&... args) {
- lock.lock();
- bool ret = (p->*func)(args...);
- lock.unlock();
- return ret;
- }
- private:
- std::mutex lock;
- };
|