| 30 | |
| 31 | struct ThreadImpl { |
| 32 | static void* runThread(void* data) { |
| 33 | ThreadImpl* ptr = static_cast<ThreadImpl*>(data); |
| 34 | try { |
| 35 | #ifdef STAR_SYSTEM_MACOS |
| 36 | // ensure the name is under the max allowed |
| 37 | char tname[MAX_THREAD_NAMELEN]; |
| 38 | snprintf(tname, sizeof(tname), "%s", ptr->name.utf8Ptr()); |
| 39 | |
| 40 | pthread_setname_np(tname); |
| 41 | #endif |
| 42 | ptr->function(); |
| 43 | } catch (std::exception const& e) { |
| 44 | if (ptr->name.empty()) |
| 45 | Logger::error("Exception caught in Thread: {}", outputException(e, true)); |
| 46 | else |
| 47 | Logger::error("Exception caught in Thread {}: {}", ptr->name, outputException(e, true)); |
| 48 | } catch (...) { |
| 49 | if (ptr->name.empty()) |
| 50 | Logger::error("Unknown exception caught in Thread"); |
| 51 | else |
| 52 | Logger::error("Unknown exception caught in Thread {}", ptr->name); |
| 53 | } |
| 54 | ptr->stopped = true; |
| 55 | return nullptr; |
| 56 | } |
| 57 | |
| 58 | ThreadImpl(std::function<void()> function, String name) |
| 59 | : function(std::move(function)), name(std::move(name)), stopped(true), joined(true) {} |
nothing calls this directly
no test coverage detected