Skip to content

Commit

Permalink
Convert example to new shared ptr interface
Browse files Browse the repository at this point in the history
  • Loading branch information
P-p-H-d committed Nov 16, 2024
1 parent 0f9edaa commit f21d427
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions example/ex-buffer01.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <stdio.h>

#include "m-buffer.h"
#include "m-shared.h"
#include "m-shared-ptr.h"
#include "m-thread.h"

/* Global variable to stop scheduling */
Expand Down Expand Up @@ -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:
*
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit f21d427

Please sign in to comment.