2
0

CThreadHelper.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * CThreadHelper.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. /// Sets thread name that will be used for both logs and debugger (if supported)
  13. /// WARNING: on Unix-like systems this method should not be used for main thread since it will also change name of the process
  14. void DLL_LINKAGE setThreadName(const std::string &name);
  15. /// Sets thread name for use in logging only
  16. void DLL_LINKAGE setThreadNameLoggingOnly(const std::string &name);
  17. /// Returns human-readable thread name that was set before, or string form of system-provided thread ID if no human-readable name was set
  18. std::string DLL_LINKAGE getThreadName();
  19. class DLL_LINKAGE ScopedThreadName : boost::noncopyable
  20. {
  21. public:
  22. ScopedThreadName(const std::string & name)
  23. {
  24. setThreadName(name);
  25. }
  26. ~ScopedThreadName()
  27. {
  28. setThreadName({});
  29. }
  30. };
  31. VCMI_LIB_NAMESPACE_END