From 66a0e6e0caccf66afc0667567aa6f6ab0ecf6375 Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Mon, 18 Jan 2010 19:58:31 +0100 Subject: [PATCH] Experiment: remove custom states, syncs are 2-thread barriers --- src/backend/threads.c | 12 ++++++------ src/backend/threads.h | 25 +++++++++++++------------ 2 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/backend/threads.c b/src/backend/threads.c index dfbcdadfe..4aeebbf23 100644 --- a/src/backend/threads.c +++ b/src/backend/threads.c @@ -288,14 +288,14 @@ lumiera_thread_deadline_clear (void) LumieraThread -lumiera_thread_sync_other (LumieraThread other, int state) +lumiera_thread_sync_other (LumieraThread other) { TRACE(threads); LUMIERA_CONDITION_SECTION (threads, &other->signal) { - REQUIRE (other->state == ~state); TODO("Runtime error when state expectation isnt met"); - other->state = state; + REQUIRE (other->state == LUMIERA_THREADSTATE_SYNCING); TODO("Runtime error when state expectation isnt met"); + other->state = LUMIERA_THREADSTATE_RUNNING; LUMIERA_CONDITION_SIGNAL; } return other; @@ -303,18 +303,18 @@ lumiera_thread_sync_other (LumieraThread other, int state) LumieraThread -lumiera_thread_sync (int state) +lumiera_thread_sync (void) { TRACE(threads); LumieraThread self = lumiera_thread_self (); REQUIRE(self, "not a lumiera thread"); - self->state = ~state; + self->state = LUMIERA_THREADSTATE_SYNCING; TODO("error handing, maybe timed mutex (using the threads heartbeat timeout, shortly before timeout)"); - while (self->state != state) { + while (self->state == LUMIERA_THREADSTATE_SYNCING) { lumiera_condition_wait (&self->signal, &NOBUG_FLAG(threads), self->rh); } diff --git a/src/backend/threads.h b/src/backend/threads.h index 131d25911..980a168e3 100644 --- a/src/backend/threads.h +++ b/src/backend/threads.h @@ -103,6 +103,7 @@ extern const char* lumiera_threadclass_names[]; LUMIERA_THREAD_STATE(ERROR) \ LUMIERA_THREAD_STATE(IDLE) \ LUMIERA_THREAD_STATE(RUNNING) \ + LUMIERA_THREAD_STATE(SYNCING) \ LUMIERA_THREAD_STATE(WAKEUP) \ LUMIERA_THREAD_STATE(SHUTDOWN) \ LUMIERA_THREAD_STATE(ZOMBIE) \ @@ -118,9 +119,6 @@ extern const char* lumiera_threadclass_names[]; typedef enum { LUMIERA_THREAD_STATES - - LUMIERA_THREADSTATE_CUSTOM_START = 1024, - LUMIERA_THREADSTATE_CUSTOM_END = 32768, } lumiera_thread_state; @@ -152,7 +150,7 @@ struct lumiera_thread_struct int kind; // this is used both as a command and as a state tracker - int state; + lumiera_thread_state state; void (*function)(void *); void * arguments; }; @@ -249,30 +247,33 @@ lumiera_thread_deadline_clear (void); /** * Thread syncronization - * Lumiera threads can be syncronized with custom states. * The syncronization primitives act as barrier over 2 threads, any thread reaching a syncronization - * point first is blocked until the other one reaches it with the same state. - * Providing different states is errorneous! + * point first is blocked until the other one reaches it too. */ /** * Syncronize with another threads state * - * this blocks until/unless the other thread reaches 'state' + * this blocks until/unless the other thread reaches a syncronization point */ LumieraThread -lumiera_thread_sync_other (LumieraThread other, int state); +lumiera_thread_sync_other (LumieraThread other); /** * Syncronize current thread * - * signifies that this thread reached 'state' and blocks until/unless - * some other thread synced with this state + * this blocks until/unless the other thread reaches a syncronization point * @return on success pointer to self (opaque), or NULL on error */ LumieraThread -lumiera_thread_sync (int state); +lumiera_thread_sync (void); + +// TODO implement timedsync, this is bit tricky because after a timeout, syncronization points are desynced +// we possibly need some way to reset/resync this +//LumieraThread +//lumiera_thread_timedsync (struct timespec timeout); + /** * Joining threads