mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 10:08:18 +00:00
Add assertions to ensure that thread_init
is successful
Ensure that `pthread_create`/`CreateThread` are successful.
This commit is contained in:
parent
788a2ad1ff
commit
97c1046104
|
@ -824,16 +824,14 @@ void *thread_init(void (*threadfunc)(void *), void *u, const char *name)
|
||||||
#if defined(CONF_PLATFORM_MACOS) && defined(__MAC_10_10) && __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10
|
#if defined(CONF_PLATFORM_MACOS) && defined(__MAC_10_10) && __MAC_OS_X_VERSION_MIN_REQUIRED >= __MAC_10_10
|
||||||
pthread_attr_set_qos_class_np(&attr, QOS_CLASS_USER_INTERACTIVE, 0);
|
pthread_attr_set_qos_class_np(&attr, QOS_CLASS_USER_INTERACTIVE, 0);
|
||||||
#endif
|
#endif
|
||||||
int result = pthread_create(&id, &attr, thread_run, data);
|
dbg_assert(pthread_create(&id, &attr, thread_run, data) == 0, "pthread_create failure");
|
||||||
if(result != 0)
|
|
||||||
{
|
|
||||||
dbg_msg("thread", "creating %s thread failed: %d", name, result);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return (void *)id;
|
return (void *)id;
|
||||||
}
|
}
|
||||||
#elif defined(CONF_FAMILY_WINDOWS)
|
#elif defined(CONF_FAMILY_WINDOWS)
|
||||||
return CreateThread(NULL, 0, thread_run, data, 0, NULL);
|
HANDLE thread = CreateThread(nullptr, 0, thread_run, data, 0, nullptr);
|
||||||
|
dbg_assert(thread != nullptr, "CreateThread failure");
|
||||||
|
// TODO: Set thread name using SetThreadDescription (would require minimum Windows 10 version 1607)
|
||||||
|
return thread;
|
||||||
#else
|
#else
|
||||||
#error not implemented
|
#error not implemented
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue