Rename worker_block_t into worker_sync_t
as it is a synchronization point for workers not an anonymous block.
This commit is contained in:
1 parent
adc7545a42
commit
f2344c69ca
3 files changed
+16
-12
No files matched your search
@@ -3296,7 +3296,7 @@ Example:
|
||||
|
||||
worker_t worker;
|
||||
worker_init(worker, 0, 0, NULL);
|
||||
worker_block_t sync;
|
||||
worker_sync_t sync;
|
||||
void *data = ...;
|
||||
worker_spawn (worker, sync, taskFunc, data);
|
||||
taskFunc(otherData);
|
||||
@@ -3310,6 +3310,10 @@ The following methods are available:
|
||||
|
||||
A pool of worker.
|
||||
|
||||
#### worker\_sync\_t
|
||||
|
||||
A synchronization point between workers.
|
||||
|
||||
#### void worker\_init(worker\_t worker, unsigned int numWorker, unsigned int extraQueue, void (*resetFunc)(void))
|
||||
|
||||
Initialize the pool of workers 'worker' with 'numWorker' workers.
|
||||
|
||||
+9
-9
@@ -80,7 +80,7 @@
|
||||
|
||||
/* This type defines a work order */
|
||||
typedef struct work_order_s {
|
||||
struct worker_block_s *block;
|
||||
struct worker_sync_s *block;
|
||||
void * data;
|
||||
void (*func) (void *data);
|
||||
#if WORKER_USE_CLANG_BLOCK
|
||||
@@ -109,10 +109,10 @@ typedef struct worker_thread_s {
|
||||
} worker_thread_t;
|
||||
|
||||
/* This type defines a synchronization point for workers */
|
||||
typedef struct worker_block_s {
|
||||
typedef struct worker_sync_s {
|
||||
atomic_int num_spawn;
|
||||
atomic_int num_terminated_spawn;
|
||||
} worker_block_t[1];
|
||||
} worker_sync_t[1];
|
||||
|
||||
/* Let's define the queue which will manage all work orders */
|
||||
BUFFER_DEF(worker_queue, worker_order_t, 0, BUFFER_QUEUE|BUFFER_UNBLOCKING_PUSH|BUFFER_BLOCKING_POP|BUFFER_THREAD_SAFE|BUFFER_DEFERRED_POP, M_POD_OPLIST)
|
||||
@@ -227,7 +227,7 @@ worker_clear(worker_t g)
|
||||
/* Start a new collaboration between workers
|
||||
and define the synchronization point 'block' */
|
||||
static inline void
|
||||
worker_start(worker_block_t block)
|
||||
worker_start(worker_sync_t block)
|
||||
{
|
||||
atomic_init (&block->num_spawn, 0);
|
||||
atomic_init (&block->num_terminated_spawn, 0);
|
||||
@@ -236,7 +236,7 @@ worker_start(worker_block_t block)
|
||||
/* Spawn or not the given work order to workers,
|
||||
or do it ourself if no worker is available */
|
||||
static inline void
|
||||
worker_spawn(worker_t g, worker_block_t block, void (*func)(void *data), void *data)
|
||||
worker_spawn(worker_t g, worker_sync_t block, void (*func)(void *data), void *data)
|
||||
{
|
||||
const worker_order_t w = { block, data, func WORKER_EXTRA_ORDER };
|
||||
if (M_UNLIKELY (!worker_queue_full_p(g->queue_g))
|
||||
@@ -254,7 +254,7 @@ worker_spawn(worker_t g, worker_block_t block, void (*func)(void *data), void *d
|
||||
/* Spawn or not the given work order to workers,
|
||||
or do it ourself if no worker is available */
|
||||
static inline void
|
||||
worker_spawn_block(worker_t g, worker_block_t block, void (^func)(void *data), void *data)
|
||||
worker_spawn_block(worker_t g, worker_sync_t block, void (^func)(void *data), void *data)
|
||||
{
|
||||
const worker_order_t w = { block, data, NULL, func };
|
||||
if (M_UNLIKELY (!worker_queue_full_p(g->queue_g))
|
||||
@@ -273,7 +273,7 @@ worker_spawn_block(worker_t g, worker_block_t block, void (^func)(void *data), v
|
||||
/* Spawn or not the given work order to workers,
|
||||
or do it ourself if no worker is available */
|
||||
static inline void
|
||||
worker_spawn_function(worker_t g, worker_block_t block, std::function<void(void *data)> func, void *data)
|
||||
worker_spawn_function(worker_t g, worker_sync_t block, std::function<void(void *data)> func, void *data)
|
||||
{
|
||||
const worker_order_t w = { block, data, NULL, func };
|
||||
if (M_UNLIKELY (!worker_queue_full_p(g->queue_g))
|
||||
@@ -290,7 +290,7 @@ worker_spawn_function(worker_t g, worker_block_t block, std::function<void(void
|
||||
|
||||
/* Wait for all work orders to be finished */
|
||||
static inline void
|
||||
worker_sync(worker_block_t block)
|
||||
worker_sync(worker_sync_t block)
|
||||
{
|
||||
//printf ("Waiting for thread terminasion.\n");
|
||||
/* If the number of spawns is greated than the number
|
||||
@@ -396,7 +396,7 @@ worker_count(worker_t g)
|
||||
|
||||
typedef struct worker_block_s {
|
||||
int x;
|
||||
} worker_block_t[1];
|
||||
} worker_sync_t[1];
|
||||
|
||||
typedef struct worker_s {
|
||||
int x;
|
||||
|
||||
@@ -40,7 +40,7 @@ static int fib(int n)
|
||||
return n;
|
||||
|
||||
struct fib2_s f;
|
||||
worker_block_t b;
|
||||
worker_sync_t b;
|
||||
|
||||
worker_start(b);
|
||||
f.n = n - 2;
|
||||
@@ -70,7 +70,7 @@ static int fib2(int n)
|
||||
if (n < 2)
|
||||
return n;
|
||||
|
||||
worker_block_t b;
|
||||
worker_sync_t b;
|
||||
int y1, y2;
|
||||
worker_start(b);
|
||||
WORKER_SPAWN(w_g, b, (n), { y2 = fib2(n-2); }, (y2));
|
||||
|
||||
Reference in new issue
Block a user