diff --git a/src/backend/threads.c b/src/backend/threads.c index 5d849943f..4fe0c8ac5 100644 --- a/src/backend/threads.c +++ b/src/backend/threads.c @@ -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 { diff --git a/src/backend/threads.h b/src/backend/threads.h index 4c15a8ad8..ce9a7605b 100644 --- a/src/backend/threads.h +++ b/src/backend/threads.h @@ -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. diff --git a/tests/30backend-threadpool.tests b/tests/30backend-threadpool.tests index ca2464bfe..e4f4e4005 100644 --- a/tests/30backend-threadpool.tests +++ b/tests/30backend-threadpool.tests @@ -9,6 +9,8 @@ TEST "Acquire/Release test" basic-acquire-release <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);