kopia lustrzana https://github.com/markondej/fm_transmitter
Added lambda function for mutex unlocking
rodzic
679edbe773
commit
53164aa8c4
|
@ -466,22 +466,23 @@ void Transmitter::transmitThread()
|
||||||
uint64_t start = current;
|
uint64_t start = current;
|
||||||
|
|
||||||
bool locked = samplesMutex.try_lock();
|
bool locked = samplesMutex.try_lock();
|
||||||
while ((!locked || !samples.size()) && transmitting) {
|
auto unlock = [&]() {
|
||||||
if (locked) {
|
if (locked) {
|
||||||
samplesMutex.unlock();
|
samplesMutex.unlock();
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
while ((!locked || !samples.size()) && transmitting) {
|
||||||
|
unlock();
|
||||||
std::this_thread::sleep_for(std::chrono::microseconds(1));
|
std::this_thread::sleep_for(std::chrono::microseconds(1));
|
||||||
current = *(reinterpret_cast<volatile uint64_t *>(&timer->low));
|
current = *(reinterpret_cast<volatile uint64_t *>(&timer->low));
|
||||||
locked = samplesMutex.try_lock();
|
locked = samplesMutex.try_lock();
|
||||||
}
|
}
|
||||||
if (!transmitting) {
|
if (!transmitting) {
|
||||||
if (locked) {
|
unlock();
|
||||||
samplesMutex.unlock();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::vector<Sample> loaded(std::move(samples));
|
std::vector<Sample> loaded(std::move(samples));
|
||||||
samplesMutex.unlock();
|
unlock();
|
||||||
|
|
||||||
sampleOffset = (current - playbackStart) * sampleRate / 1000000;
|
sampleOffset = (current - playbackStart) * sampleRate / 1000000;
|
||||||
uint32_t offset = (current - start) * sampleRate / 1000000;
|
uint32_t offset = (current - start) * sampleRate / 1000000;
|
||||||
|
|
Ładowanie…
Reference in New Issue