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

Method try_acquire_for

src/platforms/arm/rp/semaphore_rp.cpp.hpp:138–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

136template<ptrdiff_t LeastMaxValue>
137template<class Rep, class Period>
138bool CountingSemaphoreRP<LeastMaxValue>::try_acquire_for(
139 const std::chrono::duration<Rep, Period>& rel_time) { // okay std namespace
140
141 if (mSpinlock == nullptr) {
142 return false;
143 }
144
145 // Convert duration to microseconds
146 auto us = std::chrono::duration_cast<std::chrono::microseconds>(rel_time); // okay std namespace
147 absolute_time_t timeout = make_timeout_time_us(us.count());
148
149 spin_lock_t* spinlock = static_cast<spin_lock_t*>(mSpinlock);
150
151 // Spin until we can decrement the count or timeout
152 while (true) {
153 u32 save = spin_lock_blocking(spinlock);
154
155 if (mCount > 0) {
156 mCount--;
157 spin_unlock(spinlock, save);
158 return true;
159 }
160
161 spin_unlock(spinlock, save);
162
163 // Check if we've timed out
164 if (time_reached(timeout)) {
165 return false;
166 }
167
168 // Yield to avoid hogging CPU
169 tight_loop_contents();
170 }
171}
172
173template<ptrdiff_t LeastMaxValue>
174template<class Clock, class Duration>

Callers 1

FL_TEST_FILEFunction · 0.45

Calls 1

countMethod · 0.45

Tested by

no test coverage detected