Convert example to new shared ptr interface
This commit is contained in:
1 parent
0f9edaa7ee
commit
f21d427de1
1 file changed
+7
-8
@@ -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 */
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user