From 12968bb78473dd49cfdc73cf8b96a85f67f2a346 Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Wed, 20 Jan 2010 00:43:11 +0100 Subject: [PATCH] thread kind and flag handling * 256 states are enough for anyone (else fix the source) * add proper masking and handling of flags --- src/backend/threadpool.c | 1 + src/backend/threads.c | 6 +++--- src/backend/threads.h | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/backend/threadpool.c b/src/backend/threadpool.c index 9de1e6d81..72a8bc32f 100644 --- a/src/backend/threadpool.c +++ b/src/backend/threadpool.c @@ -179,6 +179,7 @@ lumiera_threadpool_release_thread(LumieraThread thread) { TRACE (threadpool); REQUIRE (thread, "invalid thread given"); + thread->kind = thread->kind&0xff; REQUIRE (thread->kind < LUMIERA_THREADCLASS_COUNT, "thread belongs to an unknown pool kind: %d", thread->kind); REQUIRE (thread->state != LUMIERA_THREADSTATE_IDLE, "trying to park an already idle thread"); diff --git a/src/backend/threads.c b/src/backend/threads.c index 2ec076978..a47f3de50 100644 --- a/src/backend/threads.c +++ b/src/backend/threads.c @@ -126,7 +126,7 @@ thread_loop (void* thread) // when this is called it should have already been decided that the function // shall run in parallel, as a thread LumieraThread -lumiera_thread_run (enum lumiera_thread_class kind, +lumiera_thread_run (int kind, void (*function)(void *), void * arg, const char* purpose, @@ -136,12 +136,12 @@ lumiera_thread_run (enum lumiera_thread_class kind, // REQUIRE (function, "invalid function"); // ask the threadpool for a thread (it might create a new one) - LumieraThread self = lumiera_threadpool_acquire_thread (kind, purpose, flag); + LumieraThread self = lumiera_threadpool_acquire_thread (kind&0xff, purpose, flag); // set the function and data to be run self->function = function; self->arguments = arg; - + self->kind = kind; self->deadline.tv_sec = 0; // and let it really run (signal the condition var, the thread waits on it) diff --git a/src/backend/threads.h b/src/backend/threads.h index 980a168e3..cc264d188 100644 --- a/src/backend/threads.h +++ b/src/backend/threads.h @@ -73,7 +73,7 @@ enum lumiera_thread_class LUMIERA_THREAD_CLASSES /** this just denotes the number of classes listed above, it is used to create arrays **/ - LUMIERA_THREADCLASS_COUNT, + LUMIERA_THREADCLASS_COUNT, /* must be <= 256, thats easy or? */ // .. various thread flags follow /** @@ -83,12 +83,12 @@ enum lumiera_thread_class * The Thread must be very careful with locking, better don't. * TODO explain syncronization issues **/ - LUMIERA_THREAD_OR_NOT = 1<<16, + LUMIERA_THREAD_OR_NOT = 1<<8, /** * Thread must be joined finally **/ - LUMIERA_THREAD_JOINABLE = 1<<17 + LUMIERA_THREAD_JOINABLE = 1<<9 }; #undef LUMIERA_THREAD_CLASS @@ -195,7 +195,7 @@ lumiera_thread_delete (LumieraThread self); * @param flag NoBug flag used for logging the thread startup and return */ LumieraThread -lumiera_thread_run (enum lumiera_thread_class kind, +lumiera_thread_run (int kind, void (*function)(void *), void * arg, const char* purpose,