FastLED 3.9.15
Loading...
Searching...
No Matches

◆ getOrCreateId()

int fl::IdTracker::getOrCreateId ( void * ptr)

Get existing ID for pointer, or create a new one if not found.

Thread-safe.

Parameters
ptrPointer to track
Returns
Unique integer ID for this pointer

Definition at line 6 of file id_tracker.cpp.hpp.

6 {
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}
fl::flat_map< void *, int > mPointerToId
Definition id_tracker.h:91
fl::mutex mMutex
Definition id_tracker.h:88

References FL_NOEXCEPT, mMutex, mNextId, and mPointerToId.

Referenced by IdTracker().

+ Here is the caller graph for this function: