This is an archive of the discontinued LLVM Phabricator instance.

[clangd] Use a separate RunningTask flag instead of leaving a broken request on top of the queue
ClosedPublic

Authored by kadircet on Mar 10 2020, 8:54 AM.

Details

Summary

This helps us prevent races when scheduler (or any other thread) tries
to read a request while it's still running.

Diff Detail

Event Timeline

kadircet created this revision.Mar 10 2020, 8:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 10 2020, 8:54 AM
sammccall added inline comments.Mar 10 2020, 9:11 AM
clang-tools-extra/clangd/TUScheduler.cpp
279

I'd consider making this an llvm::Optional<Request> and using it as storage too. Even though it won't be accessed directly outside the main loop, I think it makes it easier to reason about the code: it emphasizes the parallel with Requests and minimizes the spooky-flags-at-a-distance effect.

612

what if the currently-running task is a write?

721

maybe assert there's no running task here?

clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
376

does this deliberately match "b" below? if not, change back to something unique?
If so, probably needs a comment.

379

This looks racy to me. What guarantees that the worker thread pulls this item off the queue and into the "running" slot before the second updateWithDiags?

kadircet updated this revision to Diff 249439.Mar 10 2020, 10:19 AM
kadircet marked 6 inline comments as done.
  • Address comments
clang-tools-extra/clangd/unittests/TUSchedulerTests.cpp
376

no it wasn't intentional just copy paste ..

sammccall accepted this revision.Mar 10 2020, 10:23 AM
This revision is now accepted and ready to land.Mar 10 2020, 10:23 AM
This revision was automatically updated to reflect the committed changes.