CThreadHelper.h 763 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. /*
  3. * CThreadHelper.h, part of VCMI engine
  4. *
  5. * Authors: listed in file AUTHORS in main folder
  6. *
  7. * License: GNU General Public License v2.0 or later
  8. * Full text of license available in license.txt file, in main folder
  9. *
  10. */
  11. typedef std::function<void()> Task;
  12. /// Can assign CPU work to other threads/cores
  13. class DLL_LINKAGE CThreadHelper
  14. {
  15. boost::mutex rtinm;
  16. int currentTask, amount, threads;
  17. std::vector<Task> *tasks;
  18. void processTasks();
  19. public:
  20. CThreadHelper(std::vector<std::function<void()> > *Tasks, int Threads);
  21. void run();
  22. };
  23. template <typename T> inline void setData(T * data, std::function<T()> func)
  24. {
  25. *data = func();
  26. }
  27. void DLL_LINKAGE setThreadName(const std::string &name);