Port to new memory model:
Communication thread buffer needs to use the global pool, and not a local pool, since the allocation is done accross several threads. Therefore the non thread fixed queue & stack interfaces are moved into a dedicated header (m-queue) and remove support for non thread stack & queue into m-buffer Remove also deprecated policy too.
This commit is contained in:
1 parent
a7294abe0c
commit
01f5228a36
10 files changed
+224
-371
No files matched your search
+10
-11
@@ -142,8 +142,7 @@ typedef struct m_work3r_thread_s {
|
||||
} m_work3r_thread_ct;
|
||||
|
||||
/* Definition of the queue that will record the work orders */
|
||||
M_BUFFER_DEF(m_work3r_queue, m_work3r_order_ct, 0,
|
||||
M_BUFFER_QUEUE|M_BUFFER_UNBLOCKING_PUSH|M_BUFFER_BLOCKING_POP|M_BUFFER_THREAD_SAFE|M_BUFFER_DEFERRED_POP, M_WORK3R_OPLIST)
|
||||
M_BUFFER_DEF(m_work3r_queue, m_work3r_order_ct, 0, M_BUFFER_QUEUE|M_BUFFER_DEFERRED_POP, M_WORK3R_OPLIST)
|
||||
|
||||
/* Definition the global pool of workers */
|
||||
typedef struct m_worker_s {
|
||||
@@ -273,7 +272,7 @@ typedef struct m_worker_sync_s {
|
||||
p->callback = callback; \
|
||||
M_MAP3(M_WORK3R_SPAWN_EXTEND_DEF_EMPLACE_FIELD_INIT_SET, data, __VA_ARGS__) \
|
||||
const m_work3r_order_ct w = { block, p, M_C3(m_work3r_, name, _callback) M_WORK3R_EXTRA_ORDER }; \
|
||||
if (m_work3r_queue_push M_R(block->worker->queue_g, w) == true) { \
|
||||
if (m_work3r_queue_push_blocking (block->worker->queue_g, w, false) == true) { \
|
||||
atomic_fetch_add (&block->num_spawn, 1); \
|
||||
return; \
|
||||
} \
|
||||
@@ -372,7 +371,7 @@ m_work3r_thread(void *arg)
|
||||
}
|
||||
// Waiting for data
|
||||
M_WORK3R_DEBUG ("Waiting for data (queue: %lu / %lu)\n", m_work3r_queue_size(g->queue_g), m_work3r_queue_capacity(g->queue_g));
|
||||
m_work3r_queue_pop M_R(&w, g->queue_g);
|
||||
m_work3r_queue_pop (&w, g->queue_g);
|
||||
// We received a work order
|
||||
// Note: that the work order is still present in the queue
|
||||
// preventing further work order to be pushed in the queue until it finishes doing the work
|
||||
@@ -417,7 +416,7 @@ m_worker_init(m_worker_t g, int numWorker, unsigned int extraQueue, void (*reset
|
||||
if (M_UNLIKELY_NOMEM (g->worker == NULL)) {
|
||||
M_MEMORY_FULL(m_work3r_thread_ct, numWorker_st);
|
||||
}
|
||||
m_work3r_queue_init M_R(g->queue_g, numWorker_st + extraQueue);
|
||||
m_work3r_queue_init (g->queue_g, numWorker_st + extraQueue);
|
||||
g->numWorker_g = (unsigned int) numWorker_st;
|
||||
g->resetFunc_g = resetFunc;
|
||||
g->clearFunc_g = clearFunc;
|
||||
@@ -451,7 +450,7 @@ m_worker_clear(m_worker_t g)
|
||||
// Normally all worker threads shall be waiting at this
|
||||
// stage, so all push won't block as the queue is empty.
|
||||
// But for robustness, let's wait.
|
||||
m_work3r_queue_push_blocking M_R(g->queue_g, w, true);
|
||||
m_work3r_queue_push_blocking (g->queue_g, w, true);
|
||||
}
|
||||
// Wait for thread termination
|
||||
for(unsigned int i = 0; i < g->numWorker_g; i++) {
|
||||
@@ -461,7 +460,7 @@ m_worker_clear(m_worker_t g)
|
||||
M_MEMORY_FREE(m_work3r_thread_ct, g->worker, g->numWorker_g);
|
||||
m_mutex_clear(g->lock);
|
||||
m_cond_clear(g->a_thread_ends);
|
||||
m_work3r_queue_clear M_R(g->queue_g);
|
||||
m_work3r_queue_clear (g->queue_g);
|
||||
}
|
||||
|
||||
/* Start a new collaboration between workers of pool 'g'
|
||||
@@ -485,7 +484,7 @@ m_worker_spawn(m_worker_sync_t block, void (*func)(void *data), void *data)
|
||||
const m_work3r_order_ct w = { block, data, func M_WORK3R_EXTRA_ORDER };
|
||||
M_GLOBAL_POOL();
|
||||
if (M_UNLIKELY (!m_work3r_queue_full_p(block->worker->queue_g))
|
||||
&& m_work3r_queue_push M_R(block->worker->queue_g, w) == true) {
|
||||
&& m_work3r_queue_push_blocking (block->worker->queue_g, w, false) == true) {
|
||||
M_WORK3R_DEBUG ("Sending data to thread: %p (block: %d / %d)\n", data, block->num_spawn, block->num_terminated_spawn);
|
||||
atomic_fetch_add (&block->num_spawn, 1);
|
||||
return;
|
||||
@@ -504,7 +503,7 @@ m_work3r_spawn_block(m_worker_sync_t block, void (^func)(void *data), void *data
|
||||
const m_work3r_order_ct w = { block, data, NULL, func };
|
||||
M_GLOBAL_POOL();
|
||||
if (M_UNLIKELY (!m_work3r_queue_full_p(block->worker->queue_g))
|
||||
&& m_work3r_queue_push M_R(block->worker->queue_g, w) == true) {
|
||||
&& m_work3r_queue_push_blocking (block->worker->queue_g, w, false) == true) {
|
||||
M_WORK3R_DEBUG ("Sending data to thread as block: %p (block: %d / %d)\n", data, block->num_spawn, block->num_terminated_spawn);
|
||||
atomic_fetch_add (&block->num_spawn, 1);
|
||||
return;
|
||||
@@ -524,7 +523,7 @@ m_work3r_spawn_function(m_worker_sync_t block, std::function<void(void *data)> f
|
||||
const m_work3r_order_ct w = { block, data, NULL, func };
|
||||
M_GLOBAL_POOL();
|
||||
if (M_UNLIKELY (!m_work3r_queue_full_p(block->worker->queue_g))
|
||||
&& m_work3r_queue_push M_R(block->worker->queue_g, w) == true) {
|
||||
&& m_work3r_queue_push_blocking (block->worker->queue_g, w, false) == true) {
|
||||
M_WORK3R_DEBUG ("Sending data to thread as block: %p (block: %d / %d)\n", data, block->num_spawn, block->num_terminated_spawn);
|
||||
atomic_fetch_add (&block->num_spawn, 1);
|
||||
return;
|
||||
@@ -566,7 +565,7 @@ m_worker_flush(m_worker_t g)
|
||||
{
|
||||
m_work3r_order_ct w;
|
||||
M_GLOBAL_POOL();
|
||||
while (m_work3r_queue_pop_blocking M_R(&w, g->queue_g, false) == true) {
|
||||
while (m_work3r_queue_pop_blocking (&w, g->queue_g, false) == true) {
|
||||
m_work3r_exec(&w);
|
||||
m_work3r_queue_pop_release(g->queue_g);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user