convert lumiera_thread_class to using the enum string trick and use it in a test
This commit is contained in:
parent
98519c57da
commit
fc16de332f
4 changed files with 33 additions and 13 deletions
|
|
@ -46,6 +46,13 @@ NOBUG_DEFINE_FLAG_PARENT (threads, threads_dbg); /*TODO insert a suitable/better
|
|||
|
||||
//code goes here//
|
||||
|
||||
#define LUMIERA_THREAD_CLASS(name) #name,
|
||||
// enum string trick: expands as an array of thread class name strings
|
||||
const char* lumiera_threadclass_names[] = {
|
||||
LUMIERA_THREAD_CLASSES
|
||||
};
|
||||
|
||||
#undef LUMIERA_THREAD_CLASS
|
||||
|
||||
struct lumiera_thread_mockup
|
||||
{
|
||||
|
|
|
|||
|
|
@ -46,6 +46,21 @@
|
|||
typedef struct lumiera_thread_struct lumiera_thread;
|
||||
typedef lumiera_thread* LumieraThread;
|
||||
|
||||
// this is used for an enum string trick
|
||||
#define LUMIERA_THREAD_CLASSES \
|
||||
/** mostly idle, low latency **/ \
|
||||
LUMIERA_THREAD_CLASS(INTERACTIVE) \
|
||||
/** busy at average priority **/ \
|
||||
LUMIERA_THREAD_CLASS(WORKER) \
|
||||
/** busy, soft realtime, high priority **/ \
|
||||
LUMIERA_THREAD_CLASS(URGENT) \
|
||||
/** high latency, background jobs **/ \
|
||||
LUMIERA_THREAD_CLASS(BATCH) \
|
||||
/** Something to do when there is really nothing else to do **/ \
|
||||
LUMIERA_THREAD_CLASS(IDLE)
|
||||
|
||||
// enum string trick: expands as an enum of thread classes
|
||||
#define LUMIERA_THREAD_CLASS(name) LUMIERA_THREADCLASS_##name,
|
||||
|
||||
/**
|
||||
* Thread classes.
|
||||
|
|
@ -54,16 +69,7 @@ typedef lumiera_thread* LumieraThread;
|
|||
*/
|
||||
enum lumiera_thread_class
|
||||
{
|
||||
/** mostly idle, low latency **/
|
||||
LUMIERA_THREADCLASS_INTERACTIVE,
|
||||
/** busy at average priority **/
|
||||
LUMIERA_THREADCLASS_WORKER,
|
||||
/** busy, soft realtime, high priority **/
|
||||
LUMIERA_THREADCLASS_URGENT,
|
||||
/** high latency, background jobs **/
|
||||
LUMIERA_THREADCLASS_BATCH,
|
||||
/** Something to do when there is really nothing else to do **/
|
||||
LUMIERA_THREADCLASS_IDLE,
|
||||
LUMIERA_THREAD_CLASSES
|
||||
/** this just denotes the number of classes listed above,
|
||||
it is used to create arrays **/
|
||||
LUMIERA_THREADCLASS_COUNT,
|
||||
|
|
@ -79,6 +85,11 @@ enum lumiera_thread_class
|
|||
LUMIERA_THREAD_OR_NOT = 1<<16
|
||||
};
|
||||
|
||||
#undef LUMIERA_THREAD_CLASS
|
||||
|
||||
// defined in threads.c
|
||||
extern const char* lumiera_threadclass_names[];
|
||||
|
||||
/**
|
||||
* Thread state.
|
||||
* These are the only states our threads can be in.
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ TEST "Acquire/Release test" basic-acquire-release <<END
|
|||
err: start by initializing the threadpool
|
||||
err: acquiring thread 1
|
||||
err: acquiring thread 2
|
||||
err: thread 1 kind=INTERACTIVE
|
||||
err: thread 2 kind=IDLE
|
||||
err: releasing thread 1
|
||||
err: thread 1 has been released
|
||||
err: releasing thread 2
|
||||
|
|
|
|||
|
|
@ -44,12 +44,12 @@ TEST ("basic-acquire-release")
|
|||
"test purpose",
|
||||
NULL);
|
||||
|
||||
//ECHO("thread 1 kind=%d", t1->kind);
|
||||
ECHO("thread 1 kind=%s", lumiera_threadclass_names[t1->kind]);
|
||||
CHECK(LUMIERA_THREADCLASS_INTERACTIVE == t1->kind);
|
||||
//ECHO("thread 1 state=%d", t1->state);
|
||||
CHECK(LUMIERA_THREADSTATE_IDLE == t1->state);
|
||||
//ECHO("thread 2 kind=%d", t2->kind);
|
||||
CHECK(LUMIERA_THREADCLASS_IDLE == t2->kind);
|
||||
ECHO("thread 2 kind=%s", lumiera_threadclass_names[t2->kind]);
|
||||
CHECK(LUMIERA_THREADCLASS_IDLE == t2->kind);
|
||||
//ECHO("thread 2 state=%d", t2->state);
|
||||
CHECK(LUMIERA_THREADSTATE_IDLE == t2->state);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue