updated test passes

fixed problem with copying lists
This commit is contained in:
Michael Ploujnikov 2009-11-23 19:47:20 -05:00
parent 75696986e4
commit 414b8b99c3
3 changed files with 11 additions and 7 deletions

View file

@ -68,11 +68,9 @@ lumiera_threadpool_acquire_thread(enum lumiera_thread_class kind,
struct nobug_flag* flag) struct nobug_flag* flag)
{ {
// TODO: do we need to check that index 'kind' is within range? // 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 we need to check that we get a valid list?
// TODO: do proper locking when manipulating the 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); 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 // use an existing thread, pick the first one
// remove it from the pool's list // remove it from the pool's list
return (LumieraThread)(llist_unlink(llist_head (&pool))); return (LumieraThread)(llist_unlink(llist_head (&threadpool.kind[kind].pool)));
} }
} }

View file

@ -53,6 +53,12 @@ struct lumiera_thread_mockup
LumieraReccondition finished; LumieraReccondition finished;
}; };
static void* thread_loop (void* arg)
{
return arg;
}
#if 0
static void* pthread_runner (void* thread) static void* pthread_runner (void* thread)
{ {
pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL); pthread_setcancelstate (PTHREAD_CANCEL_DISABLE, NULL);
@ -70,6 +76,7 @@ static void* pthread_runner (void* thread)
return NULL; return NULL;
} }
#endif
static pthread_once_t attr_once = PTHREAD_ONCE_INIT; static pthread_once_t attr_once = PTHREAD_ONCE_INIT;
static pthread_attr_t attrs; static pthread_attr_t attrs;
@ -164,8 +171,7 @@ lumiera_thread_new (enum lumiera_thread_class kind,
self->kind = kind; self->kind = kind;
self->state = LUMIERA_THREADSTATE_IDLE; self->state = LUMIERA_THREADSTATE_IDLE;
printf("creating a thread\n"); int error = pthread_create (&self->id, &attrs, &thread_loop, self);
int error = pthread_create (&self->id, &attrs, &pthread_runner, self);
if (error) if (error)
{ {

View file

@ -49,7 +49,7 @@ TEST ("basic-acquire-release")
//ECHO("thread 1 state=%d", t1->state); //ECHO("thread 1 state=%d", t1->state);
CHECK(LUMIERA_THREADSTATE_IDLE == t1->state); CHECK(LUMIERA_THREADSTATE_IDLE == t1->state);
//ECHO("thread 2 kind=%d", t2->kind); //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); //ECHO("thread 2 state=%d", t2->state);
CHECK(LUMIERA_THREADSTATE_IDLE == t2->state); CHECK(LUMIERA_THREADSTATE_IDLE == t2->state);