Skip to content

Commit

Permalink
Added lambda function for mutex unlocking
Browse files Browse the repository at this point in the history
  • Loading branch information
markondej committed Oct 3, 2019
1 parent 679edbe commit 42147f8
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions transmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,22 +466,23 @@ void Transmitter::transmitThread()
uint64_t start = current;

bool locked = samplesMutex.try_lock();
while ((!locked || !samples.size()) && transmitting) {
auto unlock = [&]() {
if (locked) {
samplesMutex.unlock();
}
};
while ((!locked || !samples.size()) && transmitting) {
unlock();
std::this_thread::sleep_for(std::chrono::microseconds(1));
current = *(reinterpret_cast<volatile uint64_t *>(&timer->low));
locked = samplesMutex.try_lock();
}
if (!transmitting) {
if (locked) {
samplesMutex.unlock();
}
unlock()
break;
}
std::vector<Sample> loaded(std::move(samples));
samplesMutex.unlock();
unlock();

sampleOffset = (current - playbackStart) * sampleRate / 1000000;
uint32_t offset = (current - start) * sampleRate / 1000000;
Expand Down

0 comments on commit 42147f8

Please sign in to comment.