Skip to content

Commit

Permalink
Actually allow multiple producers to run
Browse files Browse the repository at this point in the history
  • Loading branch information
crsib committed Mar 22, 2024
1 parent a4e1747 commit 00568b2
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions libraries/lib-cloud-audiocom/sync/MissingBlocksUploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ void MissingBlocksUploader::Cancel()

mConsumerThread.join();

// mProgressMutex can be held by the consumer thread, so we need to wait
// until it's released.
std::lock_guard lock(mProgressDataMutex);
}

Expand Down Expand Up @@ -219,29 +217,38 @@ void MissingBlocksUploader::ProducerThread()
{
while (mIsRunning.load(std::memory_order_consume))
{
std::lock_guard<std::mutex> lock(mBlocksMutex);
BlockUploadTask task;

if (mFirstUnprocessedBlockIndex >= mUploadTasks.size())
return;
{
std::lock_guard<std::mutex> lock(mBlocksMutex);

if (mFirstUnprocessedBlockIndex >= mUploadTasks.size())
return;

const auto index = mFirstUnprocessedBlockIndex++;
task = std::move(mUploadTasks[index]);
}

auto item = ProduceBlock();
auto compressedData = CompressBlock(task.Block);

if (item.CompressedData.empty())
if (compressedData.empty())
{
MissingBlocksUploadProgress progressData;
{
std::lock_guard<std::mutex> lock(mProgressDataMutex);
mProgressData.FailedBlocks++;
progressData = mProgressData;
}

mProgressCallback(
progressData, item.Task.Block,
progressData, task.Block,
{ SyncResultCode::InternalClientError, {} });

return;
}

PushBlockToQueue(std::move(item));
else
{
PushBlockToQueue(
ProducedItem { std::move(task), std::move(compressedData) });
}
}
}

Expand Down

0 comments on commit 00568b2

Please sign in to comment.