FastLED 3.9.15
Loading...
Searching...
No Matches
thread_local.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/thread.h"
4
5#if FASTLED_MULTITHREADED
6#warning \
7 "ThreadLocal is not implemented, using the fake version with globally shared data"
8#endif
9
10namespace fl {
11
12template <typename T> class ThreadLocalFake;
13
14template <typename T> using ThreadLocal = ThreadLocalFake<T>;
15
17
18template <typename T> class ThreadLocalFake {
19 public:
20 // Default: each thread’s object is default-constructed
22
23 // With default: each thread’s object is copy-constructed from defaultVal
24 template <typename U>
25 explicit ThreadLocalFake(const U &defaultVal) : mValue(defaultVal) {}
26
27 // Access the thread-local instance
28 T &access() { return mValue; }
29 const T &access() const { return mValue; }
30
31 // Convenience operators for ThreadLocal<T> = x;”
32 operator T &() { return access(); }
34 set(v);
35 return *this;
36 }
37
38 private:
40};
41
42} // namespace fl
ThreadLocalFake(const U &defaultVal)
const T & access() const
ThreadLocalFake & operator=(const T &v)
ThreadLocalFake< T > ThreadLocal
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16