give each thread pool a separate pthread_attr_t structure to configure

This commit is contained in:
Michael Ploujnikov 2009-12-02 22:21:49 -05:00
parent afe135f43e
commit 098d801d00
4 changed files with 18 additions and 19 deletions

View file

@ -61,6 +61,12 @@ lumiera_threadpool_init(unsigned limit)
threadpool.pool[i].max_threads = limit;
threadpool.pool[i].working_thread_count = 0;
threadpool.pool[i].idle_thread_count = 0;
//TODO: configure each pools' pthread_attrs appropriately
pthread_attr_init (&threadpool.pool[i].pthread_attrs);
pthread_attr_setdetachstate (&threadpool.pool[i].pthread_attrs, PTHREAD_CREATE_DETACHED);
//cancel...
lumiera_mutex_init(&threadpool.pool[i].lock,"pool of threads", &NOBUG_FLAG(threadpool));
}
}
@ -79,6 +85,7 @@ lumiera_threadpool_destroy(void)
ECHO ("destroying the pool mutex");
lumiera_mutex_destroy (&threadpool.pool[i].lock, &NOBUG_FLAG (threadpool));
ECHO ("pool mutex destroyed");
pthread_attr_destroy (&threadpool.pool[i].pthread_attrs);
}
}
@ -97,7 +104,8 @@ lumiera_threadpool_acquire_thread(enum lumiera_thread_class kind,
if (threadpool.pool[kind].working_thread_count
+ threadpool.pool[kind].idle_thread_count
< threadpool.pool[kind].max_threads) {
ret = lumiera_thread_new (kind, NULL, purpose, flag);
ret = lumiera_thread_new (kind, NULL, purpose, flag,
&threadpool.pool[kind].pthread_attrs);
threadpool.pool[kind].working_thread_count++;
ENSURE (ret, "did not create a valid thread");
}

View file

@ -74,6 +74,7 @@ struct lumiera_threadpool_struct
unsigned max_threads;
unsigned working_thread_count;
unsigned idle_thread_count;
pthread_attr_t pthread_attrs;
} pool[LUMIERA_THREADCLASS_COUNT];
};

View file

@ -93,16 +93,6 @@ static void* pthread_runner (void* thread)
}
#endif
static pthread_once_t attr_once = PTHREAD_ONCE_INIT;
static pthread_attr_t attrs;
static void thread_attr_init (void)
{
pthread_attr_init (&attrs);
pthread_attr_setdetachstate (&attrs, PTHREAD_CREATE_DETACHED);
//cancel ...
}
#if 0
// TODO: rewrite this using lumiera_threadpool_acquire()
LumieraThread
@ -171,27 +161,26 @@ LumieraThread
lumiera_thread_new (enum lumiera_thread_class kind,
LumieraReccondition finished,
const char* purpose,
struct nobug_flag* flag)
struct nobug_flag* flag,
pthread_attr_t* attrs)
{
// TODO: do something with these:
(void) purpose;
(void) flag;
REQUIRE (kind < LUMIERA_THREADCLASS_COUNT, "invalid thread kind specified: %d", kind);
if (attr_once == PTHREAD_ONCE_INIT)
pthread_once (&attr_once, thread_attr_init);
REQUIRE (attrs, "invalid pthread attributes structure passed");
//REQUIRE (finished, "invalid finished flag passed");
LumieraThread self = lumiera_malloc (sizeof (*self));
llist_init(&self->node);
self->finished = finished;
self->kind = kind;
self->state = LUMIERA_THREADSTATE_IDLE;
//REQUIRE (&attrs);
//REQUIRE (&thread_loop);
int error = pthread_create (&self->id, &attrs, &thread_loop, self);
//REQUIRE (thread_loop);
int error = pthread_create (&self->id, attrs, &thread_loop, self);
ENSURE(error == 0 || EAGAIN == error, "pthread returned %d:%s", error, strerror(error));
if (error)
{

View file

@ -139,7 +139,8 @@ LumieraThread
lumiera_thread_new (enum lumiera_thread_class kind,
LumieraReccondition finished,
const char* purpose,
struct nobug_flag* flag);
struct nobug_flag* flag,
pthread_attr_t* attrs);
LumieraThread
lumiera_thread_destroy (LumieraThread self);