Skip to content

Commit b271e7d

Browse files
committed
hold pointer, not objects in the container
1 parent 0c405f3 commit b271e7d

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

StaticThreadController.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@
2121
template <int N>
2222
class StaticThreadController: public Thread{
2323
protected:
24-
Thread thread[N];
24+
//since this is a static controller, the pointers themselves can be const
25+
//it should be distinguished from 'const Thread* thread[N]'
26+
Thread * const thread[N];
2527
public:
2628
template <typename... T>
27-
StaticThreadController(T&&... params) :
29+
StaticThreadController(T... params) :
2830
Thread(),
2931
thread{params...}
3032
{
@@ -40,8 +42,8 @@ class StaticThreadController: public Thread{
4042
{
4143
for(int i = 0; i < N; i++){
4244
// Is enabled? Timeout exceeded?
43-
if(thread[i].shouldRun()){
44-
thread[i].run();
45+
if(thread[i]->shouldRun()){
46+
thread[i]->run();
4547
}
4648
}
4749

@@ -54,12 +56,16 @@ class StaticThreadController: public Thread{
5456

5557
// Return the I Thread on the array
5658
// Returns nullptr if index is out of bounds
57-
Thread* get(int index) { return (index >= 0 && index < N) ? &thread[index] : nullptr; };
59+
Thread* get(int index) {
60+
return (index >= 0 && index < N) ? thread[index] : nullptr;
61+
};
5862

5963
// Return the I Thread on the array
6064
// Doesn't perform any bounds checks and behaviour is
6165
// unpredictable in case of index > N
62-
Thread& operator[](int index) { return thread[index]; };
66+
Thread& operator[](int index) {
67+
return *thread[index];
68+
};
6369
};
6470

6571
#endif

0 commit comments

Comments
 (0)