From f21d427de1cbb9c89dbe6722fc3e72a04b5b1f1b Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sat, 16 Nov 2024 18:02:13 +0100 Subject: [PATCH] Convert example to new shared ptr interface --- example/ex-buffer01.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/example/ex-buffer01.c b/example/ex-buffer01.c index 685f8093..f038e5d5 100644 --- a/example/ex-buffer01.c +++ b/example/ex-buffer01.c @@ -1,7 +1,7 @@ #include #include "m-buffer.h" -#include "m-shared.h" +#include "m-shared-ptr.h" #include "m-thread.h" /* Global variable to stop scheduling */ @@ -99,8 +99,8 @@ SHARED_PTR_DEF(shared_bigdata, bigdata_t) * - we change the semantics of _push / _pop into buffer as push a new item and pop it as a move (ideal semantics for shared_ptr interface). */ #define MY_QUEUE_SIZE 10 -BUFFER_DEF(buffer_bigdata, shared_bigdata_t, MY_QUEUE_SIZE, - BUFFER_QUEUE|BUFFER_PUSH_INIT_POP_MOVE, SHARED_PTR_OPLIST(shared_bigdata)) +BUFFER_DEF(buffer_bigdata, shared_bigdata_t *, MY_QUEUE_SIZE, + BUFFER_QUEUE|BUFFER_PUSH_INIT_POP_MOVE, SHARED_PTR_OPLIST(shared_bigdata, M_OPL_bigdata_t())) /* Let's build a Thread synchros tree: * @@ -134,8 +134,7 @@ static void thread1 (void *arg) { (void) arg; while (atomic_load(&continue_threading_g)) { - shared_bigdata_t ptr; - shared_bigdata_init_new (ptr); + shared_bigdata_t *ptr = shared_bigdata_new (); perform_acquisition(*shared_bigdata_ref(ptr)); buffer_bigdata_push(buf_t1tot2, ptr); buffer_bigdata_push(buf_t1tot3, ptr); @@ -146,7 +145,7 @@ static void thread2 (void *arg) { (void) arg; while (atomic_load(&continue_threading_g)) { - shared_bigdata_t ptr; + shared_bigdata_t *ptr; buffer_bigdata_pop(&ptr, buf_t1tot2); // NOTE: Pop has been configured to init ptr perform_computation2(*shared_bigdata_ref(ptr)); shared_bigdata_clear(ptr); @@ -156,7 +155,7 @@ static void thread3 (void *arg) { (void) arg; while (atomic_load(&continue_threading_g)) { - shared_bigdata_t ptr; + shared_bigdata_t *ptr; buffer_bigdata_pop(&ptr, buf_t1tot3); // NOTE: Pop has been configured to init ptr perform_computation3(*shared_bigdata_ref(ptr)); buffer_bigdata_push(buf_t3tot4, ptr); @@ -167,7 +166,7 @@ static void thread4 (void *arg) { (void) arg; while (atomic_load(&continue_threading_g)) { - shared_bigdata_t ptr; + shared_bigdata_t *ptr; buffer_bigdata_pop(&ptr, buf_t3tot4); // NOTE: Pop has been configured to init ptr perform_computation4(*shared_bigdata_ref(ptr)); shared_bigdata_clear(ptr);