diff --git a/README.md b/README.md index 924d9b49..f319ec69 100644 --- a/README.md +++ b/README.md @@ -3353,9 +3353,12 @@ cannot use return / goto to go outside the flow). This macro needs either GCC (for nested function) or CLANG (for blocks) to work. -NOTE: Even if nested functions are used for GCC, it doesn't generate +NOTE1: Even if nested functions are used for GCC, it doesn't generate a trampoline and the stack doesn't need to be executable. +NOTE2: For CLANG, you need to add -fblocks to CFLAGS and -lBlocksRuntime to LIB (See CLANG manual). + +NOTE3: It will generate warnings about shadow variables. There is no way to avoid this. ### M-ALGO diff --git a/m-worker.h b/m-worker.h index c97d2cde..2333b5ad 100644 --- a/m-worker.h +++ b/m-worker.h @@ -68,6 +68,18 @@ typedef struct { #endif } worker_order_t; +/* Define the macros needed to initialize an order. + * * MACRO to be used to send an empty order to stop the thread + * * MACRO to complete the not-used fields + */ +#if WORKER_CLANG_BLOCK +# define WORKER_EMPTY_ORDER { NULL, NULL, NULL, NULL } +# define WORKER_EXTRA_ORDER , NULL +#else +# define WORKER_EMPTY_ORDER { NULL, NULL, NULL } +# define WORKER_EXTRA_ORDER +#endif + /* This type defines a worker */ typedef struct { m_thread_t id; @@ -171,7 +183,7 @@ static inline void worker_clear(worker_t g) { for(unsigned int i = 0; i < g->numWorker_g; i++) { - worker_order_t w = { NULL, NULL, NULL}; + worker_order_t w = WORKER_EMPTY_ORDER; worker_queue_push (g->queue_g, w); } @@ -197,7 +209,7 @@ worker_start(worker_block_t block) static inline void worker_spawn(worker_t g, worker_block_t block, void (*func)(void *data), void *data) { - const worker_order_t w = { block, data, func }; + const worker_order_t w = { block, data, func WORKER_EXTRA_ORDER }; if (M_UNLIKELY (!worker_queue_full_p(g->queue_g)) && worker_queue_push (g->queue_g, w) == true) { //printf ("Sending data to thread: %p (block: %d / %d)\n", data, block->num_spawn, block->num_terminated_spawn);