MCPcopy Create free account
hub / github.com/FastLED/FastLED / getOrCreateId

Method getOrCreateId

src/fl/channels/id_tracker.cpp.hpp:6–28  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4namespace fl {
5
6int IdTracker::getOrCreateId(void* ptr) FL_NOEXCEPT {
7 if (!ptr) {
8 return -1; // Invalid pointer gets invalid ID
9 }
10
11 // Lock for thread safety
12 mMutex.lock();
13
14 // Check if ID already exists
15 auto it = mPointerToId.find(ptr);
16 if (it != mPointerToId.end()) {
17 int id = it->second;
18 mMutex.unlock();
19 return id;
20 }
21
22 // Create new ID
23 int newId = mNextId++;
24 mPointerToId[ptr] = newId;
25
26 mMutex.unlock();
27 return newId;
28}
29
30bool IdTracker::getId(void* ptr, int* outId) FL_NOEXCEPT {
31 if (!ptr || !outId) {

Callers 3

onStripAddedMethod · 0.80
onCanvasUiSetMethod · 0.80
onCanvasUiSetMethod · 0.80

Calls 4

lockMethod · 0.45
findMethod · 0.45
endMethod · 0.45
unlockMethod · 0.45

Tested by

no test coverage detected