Skip to content

Commit e3e0369

Browse files
committed
Switch to std::atomic_int.
1 parent 6f5f7cb commit e3e0369

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lld/MachO/Driver.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,12 @@ void multiThreadedPageInBackground(const DeferredFiles &deferred) {
303303
std::atomic_int index = 0;
304304

305305
parallelFor(0, config->readThreads, [&](size_t I) {
306-
while (index < (int)deferred.size()) {
307-
const StringRef &buff = deferred[index].buffer.getBuffer();
306+
while (true) {
307+
int localIndex = index.fetch_add(1);
308+
if (localIndex >= (int)deferred.size())
309+
break;
310+
const StringRef &buff = deferred[localIndex].buffer.getBuffer();
308311
totalBytes += buff.size();
309-
index += 1;
310312

311313
// Reference all file's mmap'd pages to load them into memory.
312314
for (const char *page = buff.data(), *end = page + buff.size();

0 commit comments

Comments
 (0)