asyncworker.cpp 577 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "asyncworker.h"
  2. using namespace vnotex;
  3. AsyncWorker::AsyncWorker(QObject *p_parent)
  4. : QThread(p_parent)
  5. {
  6. }
  7. void AsyncWorker::stop()
  8. {
  9. m_askedToStop.store(1);
  10. }
  11. bool AsyncWorker::isAskedToStop() const
  12. {
  13. return m_askedToStop.load() == 1;
  14. }
  15. AsyncWorkerWithFunctor::AsyncWorkerWithFunctor(QObject *p_parent)
  16. : QThread(p_parent)
  17. {
  18. }
  19. void AsyncWorkerWithFunctor::doWork(const Functor &p_functor)
  20. {
  21. Q_ASSERT(!isRunning());
  22. m_functor = p_functor;
  23. start();
  24. }
  25. void AsyncWorkerWithFunctor::run()
  26. {
  27. Q_ASSERT(m_functor);
  28. m_functor();
  29. }