MCPcopy Create free account
hub / github.com/crownengine/crown / start

Method start

src/core/thread/thread.cpp:78–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

76}
77
78void Thread::start(ThreadFunction func, void *user_data, u32 stack_size)
79{
80 CE_ASSERT(!_priv->_is_running, "Thread is already running");
81 CE_ASSERT(func != NULL, "Function must be != NULL");
82 _priv->_function = func;
83 _priv->_user_data = user_data;
84
85#if CROWN_PLATFORM_WINDOWS
86 _priv->handle = CreateThread(NULL, stack_size, thread_proc, this, 0, NULL);
87 CE_ASSERT(_priv->handle != NULL, "CreateThread: GetLastError = %d", GetLastError());
88#else
89 pthread_attr_t attr;
90 int err = pthread_attr_init(&attr);
91 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
92 CE_ASSERT(err == 0, "pthread_attr_init: errno = %d", err);
93
94 if (stack_size != 0) {
95 err = pthread_attr_setstacksize(&attr, stack_size);
96 CE_ASSERT(err == 0, "pthread_attr_setstacksize: errno = %d", err);
97 }
98
99 err = pthread_create(&_priv->handle, &attr, thread_proc, this);
100 CE_ASSERT(err == 0, "pthread_create: errno = %d", err);
101
102 err = pthread_attr_destroy(&attr);
103 CE_ASSERT(err == 0, "pthread_attr_destroy: errno = %d", err);
104 CE_UNUSED(err);
105#endif // if CROWN_PLATFORM_WINDOWS
106
107 _priv->_is_running = true;
108 _priv->_sem.wait();
109}
110
111void Thread::stop()
112{

Callers 9

test_threadFunction · 0.45
test_file_monitorFunction · 0.45
ResourceLoaderMethod · 0.45
scan_and_restoreMethod · 0.45
runMethod · 0.45
runMethod · 0.45
process_commandMethod · 0.45
listenMethod · 0.45
SaveGameMethod · 0.45

Calls 1

waitMethod · 0.45

Tested by 2

test_threadFunction · 0.36
test_file_monitorFunction · 0.36