31 #include <system_threads.h>
38 #ifdef FREEWRL_THREAD_COLORIZED
57 static int threads_colors[FREEWRL_MAX_THREADS] = {
65 #define FREEWRL_DEFAULT_COLOR 37
69 DEF_THREAD(_THREAD_NULL_);
101 #ifdef DOWEREALYNEEDTHIS
102 static int fw_once = 0;
104 void threads_init(
struct tthreads* t)
122 #ifdef DOWEREALYNEEDTHIS
127 pthread_win32_process_attach_np();
133 pthread_mutex_init (&t->mutex_resource_tree,NULL);
135 pthread_mutex_init (&t->mutex_resource_list,NULL);
136 pthread_cond_init (&t->resource_list_condition,NULL);
138 pthread_mutex_init (&t->mutex_texture_list,NULL);
139 pthread_cond_init(&t->texture_list_condition,NULL);
141 pthread_mutex_init(&t->mutex_frontend_list,NULL);
144 t->ResourceThreadRunning =
false;
145 t->TextureThreadRunning =
false;
146 t->ResourceThreadWaiting =
false;
147 t->TextureThreadWaiting =
false;
168 void fwl_initializeInputParseThread()
178 pthread_mutex_init( &tg->threads.mutex_resource_tree, NULL );
179 pthread_mutex_init( &tg->threads.mutex_resource_list, NULL );
180 pthread_cond_init( &tg->threads.resource_list_condition, NULL );
181 pthread_mutex_init(&tg->threads.mutex_frontend_list,NULL);
184 ASSERT(TEST_NULL_THREAD(tg->threads.PCthread));
185 ret = pthread_create(&tg->threads.PCthread, NULL, (
void *(*)(
void *))&_inputParseThread, tg);
191 ERROR_MSG(
"initializeInputParseThread: not enough system resources to create a process for the new thread.");
196 void fwl_initializeTextureThread()
201 pthread_mutex_init( &tg->threads.mutex_texture_list, NULL );
202 pthread_cond_init( &tg->threads.texture_list_condition, NULL );
208 ASSERT(TEST_NULL_THREAD(tg->threads.loadThread));
209 ret = pthread_create(&tg->threads.loadThread, NULL, (
void *(*)(
void *))&_textureThread, tg);
215 ERROR_MSG(
"initializeTextureThread: not enough system resources to create a process for the new thread.");
222 pthread_t current_thread;
224 current_thread = pthread_self();
231 if(TEST_NULL_THREAD(current_thread)){
232 ERROR_MSG(
"Critical: pthread_self returned 0\n");
236 if (pthread_equal(current_thread, tg->threads.mainThread))
237 return FREEWRL_THREAD_MAIN;
239 if (pthread_equal(current_thread, tg->threads.DispThrd))
240 return FREEWRL_THREAD_DISPLAY;
242 if (pthread_equal(current_thread, tg->threads.PCthread))
243 return FREEWRL_THREAD_PARSER;
245 if (pthread_equal(current_thread, tg->threads.loadThread))
246 return FREEWRL_THREAD_TEXTURE;
252 #ifdef FREEWRL_THREAD_COLORIZED
254 int fw_thread_color(
int thread_id)
257 if ((thread_id > 0) && (thread_id <= FREEWRL_MAX_THREADS)) {
258 return threads_colors[ thread_id - 1 ];
260 return FREEWRL_DEFAULT_COLOR;
265 void fwl_thread_dump()
267 if (gglobal()->internalc.global_trace_threads) {
271 TRACE_MSG(
"FreeWRL CURRENT THREAD: %d\n", fw_thread_id());
275 void trace_enter_thread(
const char *str)
286 if (gglobal()->internalc.global_trace_threads) {
294 TRACE_MSG(
"*** ENTERING THREAD: %s, ID=%d self=%p\n", str, fw_thread_id(), (
void*) ID_THREAD(pthread_self()));