Experiment: remove custom states, syncs are 2-thread barriers

This commit is contained in:
Christian Thaeter 2010-01-18 19:58:31 +01:00
parent e2c5aceec4
commit 66a0e6e0ca
2 changed files with 19 additions and 18 deletions

View file

@ -288,14 +288,14 @@ lumiera_thread_deadline_clear (void)
LumieraThread LumieraThread
lumiera_thread_sync_other (LumieraThread other, int state) lumiera_thread_sync_other (LumieraThread other)
{ {
TRACE(threads); TRACE(threads);
LUMIERA_CONDITION_SECTION (threads, &other->signal) LUMIERA_CONDITION_SECTION (threads, &other->signal)
{ {
REQUIRE (other->state == ~state); TODO("Runtime error when state expectation isnt met"); REQUIRE (other->state == LUMIERA_THREADSTATE_SYNCING); TODO("Runtime error when state expectation isnt met");
other->state = state; other->state = LUMIERA_THREADSTATE_RUNNING;
LUMIERA_CONDITION_SIGNAL; LUMIERA_CONDITION_SIGNAL;
} }
return other; return other;
@ -303,18 +303,18 @@ lumiera_thread_sync_other (LumieraThread other, int state)
LumieraThread LumieraThread
lumiera_thread_sync (int state) lumiera_thread_sync (void)
{ {
TRACE(threads); TRACE(threads);
LumieraThread self = lumiera_thread_self (); LumieraThread self = lumiera_thread_self ();
REQUIRE(self, "not a lumiera thread"); 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)"); 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); lumiera_condition_wait (&self->signal, &NOBUG_FLAG(threads), self->rh);
} }

View file

@ -103,6 +103,7 @@ extern const char* lumiera_threadclass_names[];
LUMIERA_THREAD_STATE(ERROR) \ LUMIERA_THREAD_STATE(ERROR) \
LUMIERA_THREAD_STATE(IDLE) \ LUMIERA_THREAD_STATE(IDLE) \
LUMIERA_THREAD_STATE(RUNNING) \ LUMIERA_THREAD_STATE(RUNNING) \
LUMIERA_THREAD_STATE(SYNCING) \
LUMIERA_THREAD_STATE(WAKEUP) \ LUMIERA_THREAD_STATE(WAKEUP) \
LUMIERA_THREAD_STATE(SHUTDOWN) \ LUMIERA_THREAD_STATE(SHUTDOWN) \
LUMIERA_THREAD_STATE(ZOMBIE) \ LUMIERA_THREAD_STATE(ZOMBIE) \
@ -118,9 +119,6 @@ extern const char* lumiera_threadclass_names[];
typedef enum typedef enum
{ {
LUMIERA_THREAD_STATES LUMIERA_THREAD_STATES
LUMIERA_THREADSTATE_CUSTOM_START = 1024,
LUMIERA_THREADSTATE_CUSTOM_END = 32768,
} }
lumiera_thread_state; lumiera_thread_state;
@ -152,7 +150,7 @@ struct lumiera_thread_struct
int kind; int kind;
// this is used both as a command and as a state tracker // this is used both as a command and as a state tracker
int state; lumiera_thread_state state;
void (*function)(void *); void (*function)(void *);
void * arguments; void * arguments;
}; };
@ -249,30 +247,33 @@ lumiera_thread_deadline_clear (void);
/** /**
* Thread syncronization * Thread syncronization
* Lumiera threads can be syncronized with custom states.
* The syncronization primitives act as barrier over 2 threads, any thread reaching a syncronization * 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. * point first is blocked until the other one reaches it too.
* Providing different states is errorneous!
*/ */
/** /**
* Syncronize with another threads state * 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 LumieraThread
lumiera_thread_sync_other (LumieraThread other, int state); lumiera_thread_sync_other (LumieraThread other);
/** /**
* Syncronize current thread * Syncronize current thread
* *
* signifies that this thread reached 'state' and blocks until/unless * this blocks until/unless the other thread reaches a syncronization point
* some other thread synced with this state
* @return on success pointer to self (opaque), or NULL on error * @return on success pointer to self (opaque), or NULL on error
*/ */
LumieraThread 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 * Joining threads