convert lumiera_thread_state to using the enum string trick and use it in a test

This commit is contained in:
Michael Ploujnikov 2009-11-29 18:06:14 -05:00
parent fc16de332f
commit eedfafb0d0
4 changed files with 23 additions and 5 deletions

View file

@ -54,6 +54,12 @@ const char* lumiera_threadclass_names[] = {
#undef LUMIERA_THREAD_CLASS
#define LUMIERA_THREAD_STATE(name) #name,
const char* lumiera_threadstate_names[] = {
LUMIERA_THREAD_STATES
};
#undef LUMIERA_THREAD_STATE
struct lumiera_thread_mockup
{
void (*fn)(void*);

View file

@ -90,18 +90,28 @@ enum lumiera_thread_class
// defined in threads.c
extern const char* lumiera_threadclass_names[];
#define LUMIERA_THREAD_STATES \
LUMIERA_THREAD_STATE(IDLE) \
LUMIERA_THREAD_STATE(RUNNING) \
LUMIERA_THREAD_STATE(ERROR)
#define LUMIERA_THREAD_STATE(name) LUMIERA_THREADSTATE_##name,
/**
* Thread state.
* These are the only states our threads can be in.
*/
typedef enum
{
LUMIERA_THREADSTATE_IDLE,
LUMIERA_THREADSTATE_RUNNING,
LUMIERA_THREADSTATE_ERROR
LUMIERA_THREAD_STATES
}
lumiera_thread_state;
#undef LUMIERA_THREAD_STATE
// defined in threads.c
extern const char* lumiera_threadstate_names[];
#include "threadpool.h"
/**

View file

@ -10,7 +10,9 @@ err: start by initializing the threadpool
err: acquiring thread 1
err: acquiring thread 2
err: thread 1 kind=INTERACTIVE
err: thread 1 state=IDLE
err: thread 2 kind=IDLE
err: thread 2 state=IDLE
err: releasing thread 1
err: thread 1 has been released
err: releasing thread 2

View file

@ -46,11 +46,11 @@ TEST ("basic-acquire-release")
ECHO("thread 1 kind=%s", lumiera_threadclass_names[t1->kind]);
CHECK(LUMIERA_THREADCLASS_INTERACTIVE == t1->kind);
//ECHO("thread 1 state=%d", t1->state);
ECHO("thread 1 state=%s", lumiera_threadstate_names[t1->state]);
CHECK(LUMIERA_THREADSTATE_IDLE == t1->state);
ECHO("thread 2 kind=%s", lumiera_threadclass_names[t2->kind]);
CHECK(LUMIERA_THREADCLASS_IDLE == t2->kind);
//ECHO("thread 2 state=%d", t2->state);
ECHO("thread 2 state=%s", lumiera_threadstate_names[t2->state]);
CHECK(LUMIERA_THREADSTATE_IDLE == t2->state);
ECHO("releasing thread 1");