Skip to content

Commit b16f65c

Browse files
authored
Merge pull request #70 from bcmi-labs/fix-61
An upgraded 'Shared' macro allows a definition of the internal queue size on a per-object-basis.
2 parents 669f272 + 81604f5 commit b16f65c

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

Diff for: docs/02-data-exchange.md

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ A `Shared` variable is a global variable accessible to all threads. It can be de
1212
```C++
1313
/* SharedVariables.h */
1414
SHARED(counter, int); /* A globally available, threadsafe, shared variable of type 'int'. */
15+
/* ... or ... */
16+
SHARED(counter, int, 8); /* Same as before, but now the internal queue size is defined as 8. */
1517
```
1618
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.
1719
New values can be inserted naturally by using the assignment operator `=` as if it was just any ordinary variable type, i.e. `int`, `char`, ...

Diff for: src/Arduino_Threads.h

+3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ public: \
8585
#define SHARED(name, type) \
8686
Shared<type> name;
8787

88+
#define SHARED(name, type, size) \
89+
Shared<type, size> name;
90+
8891
#define ARDUINO_THREADS_CONCAT_(x,y) x##y
8992
#define ARDUINO_THREADS_CONCAT(x,y) ARDUINO_THREADS_CONCAT_(x,y)
9093

0 commit comments

Comments
 (0)