MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / runThread

Method runThread

source/core/StarThread_unix.cpp:32–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30
31struct 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) {}

Callers

nothing calls this directly

Calls 5

errorFunction · 0.85
functionMethod · 0.80
outputExceptionFunction · 0.70
utf8PtrMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected