From 3ee47b044376eb0b1103ec9ede3e0aefba597177 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 22 Jun 2022 07:01:11 +0200 Subject: [PATCH 1/2] An upgraded 'Shared' macro allows a definition of the internal queue size on a per-object-basis. This fixes #61. --- src/Arduino_Threads.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Arduino_Threads.h b/src/Arduino_Threads.h index 1750f95..1e8b85d 100644 --- a/src/Arduino_Threads.h +++ b/src/Arduino_Threads.h @@ -85,6 +85,9 @@ public: \ #define SHARED(name, type) \ Shared name; +#define SHARED(name, type, size) \ + Shared name; + #define ARDUINO_THREADS_CONCAT_(x,y) x##y #define ARDUINO_THREADS_CONCAT(x,y) ARDUINO_THREADS_CONCAT_(x,y) From 81604f5f0663938c8eb3a7ad4e1c1994778c99f0 Mon Sep 17 00:00:00 2001 From: Alexander Entinger Date: Wed, 22 Jun 2022 07:02:43 +0200 Subject: [PATCH 2/2] Extending documentation to mention the possibility of a size-configurable Shared abstraction. --- docs/02-data-exchange.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/02-data-exchange.md b/docs/02-data-exchange.md index e30aeaf..1695068 100644 --- a/docs/02-data-exchange.md +++ b/docs/02-data-exchange.md @@ -12,6 +12,8 @@ A `Shared` variable is a global variable accessible to all threads. It can be de ```C++ /* SharedVariables.h */ SHARED(counter, int); /* A globally available, threadsafe, shared variable of type 'int'. */ +/* ... or ... */ +SHARED(counter, int, 8); /* Same as before, but now the internal queue size is defined as 8. */ ``` Writing to and reading from the shared variable may not always happen concurrently. I.e. a thread reading sensor data may update the shared variable faster than a slower reader thread would extract those values. Therefore the shared variable is modeled as a queue which can store (buffer) a certain number of entries. That way the slower reader thread can access all the values in the same order as they have been written. New values can be inserted naturally by using the assignment operator `=` as if it was just any ordinary variable type, i.e. `int`, `char`, ...