| 59 | : function(std::move(function)), name(std::move(name)), stopped(true), joined(true) {} |
| 60 | |
| 61 | bool start() { |
| 62 | MutexLocker mutexLocker(mutex); |
| 63 | if (!joined) |
| 64 | return false; |
| 65 | |
| 66 | stopped = false; |
| 67 | joined = false; |
| 68 | int ret = pthread_create(&pthread, NULL, &runThread, (void*)this); |
| 69 | if (ret != 0) { |
| 70 | stopped = true; |
| 71 | joined = true; |
| 72 | throw StarException(strf("Failed to create thread, error {}", ret)); |
| 73 | } |
| 74 | |
| 75 | // ensure the name is under the max allowed |
| 76 | char tname[MAX_THREAD_NAMELEN]; |
| 77 | snprintf(tname, sizeof(tname), "%s", name.utf8Ptr()); |
| 78 | |
| 79 | #ifdef STAR_SYSTEM_FREEBSD |
| 80 | pthread_set_name_np(pthread, tname); |
| 81 | #elif defined(STAR_SYSTEM_NETBSD) |
| 82 | pthread_setname_np(pthread, "%s", tname); |
| 83 | #elif not defined STAR_SYSTEM_MACOS |
| 84 | pthread_setname_np(pthread, tname); |
| 85 | #endif |
| 86 | return true; |
| 87 | } |
| 88 | |
| 89 | bool join() { |
| 90 | MutexLocker mutexLocker(mutex); |
nothing calls this directly
no test coverage detected