From 414b8b99c341b5fd8a1891074fd1bdfaf1c8095a Mon Sep 17 00:00:00 2001 From: Michael Ploujnikov Date: Mon, 23 Nov 2009 19:47:20 -0500 Subject: [PATCH] updated test passes fixed problem with copying lists --- src/backend/threadpool.c | 6 ++---- src/backend/threads.c | 10 ++++++++-- tests/backend/test-threadpool.c | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/backend/threadpool.c b/src/backend/threadpool.c index 063794012..87ca3803c 100644 --- a/src/backend/threadpool.c +++ b/src/backend/threadpool.c @@ -68,11 +68,9 @@ lumiera_threadpool_acquire_thread(enum lumiera_thread_class kind, struct nobug_flag* flag) { // TODO: do we need to check that index 'kind' is within range? - llist pool = threadpool.kind[kind].pool; // TODO: do we need to check that we get a valid list? - // TODO: do proper locking when manipulating the list - if (llist_is_empty (&pool)) + if (llist_is_empty (&threadpool.kind[kind].pool)) { return lumiera_thread_new (kind, NULL, purpose, flag); } @@ -80,7 +78,7 @@ lumiera_threadpool_acquire_thread(enum lumiera_thread_class kind, { // use an existing thread, pick the first one // remove it from the pool's list - return (LumieraThread)(llist_unlink(llist_head (&pool))); + return (LumieraThread)(llist_unlink(llist_head (&threadpool.kind[kind].pool))); } } diff --git a/src/backend/threads.c b/src/backend/threads.c index 7b18ab70a..e87853765 100644 --- a/src/backend/threads.c +++ b/src/backend/threads.c @@ -53,6 +53,12 @@ struct lumiera_thread_mockup LumieraReccondition finished; }; +static void* thread_loop (void* arg) +{ + return arg; +} + +#if 0 static void* pthread_runner (void* thread) { pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); @@ -70,6 +76,7 @@ static void* pthread_runner (void* thread) return NULL; } +#endif static pthread_once_t attr_once = PTHREAD_ONCE_INIT; static pthread_attr_t attrs; @@ -164,8 +171,7 @@ lumiera_thread_new (enum lumiera_thread_class kind, self->kind = kind; self->state = LUMIERA_THREADSTATE_IDLE; - printf("creating a thread\n"); - int error = pthread_create (&self->id, &attrs, &pthread_runner, self); + int error = pthread_create (&self->id, &attrs, &thread_loop, self); if (error) { diff --git a/tests/backend/test-threadpool.c b/tests/backend/test-threadpool.c index 902a948c2..301688f48 100644 --- a/tests/backend/test-threadpool.c +++ b/tests/backend/test-threadpool.c @@ -49,7 +49,7 @@ TEST ("basic-acquire-release") //ECHO("thread 1 state=%d", t1->state); CHECK(LUMIERA_THREADSTATE_IDLE == t1->state); //ECHO("thread 2 kind=%d", t2->kind); - // CHECK(LUMIERA_THREAD_IDLE == t2->kind); + CHECK(LUMIERA_THREAD_IDLE == t2->kind); //ECHO("thread 2 state=%d", t2->state); CHECK(LUMIERA_THREADSTATE_IDLE == t2->state);