Commit Graph

34 Commits

Author SHA1 Message Date
Saleem Abdulrasool decfad7d8e Revert "Re-Revert "DirectoryWatcher: add an implementation for Windows""
This reverts commit fb32de9e97.

Remove the secondary synchronization point as noted by Adrian.  This is
technically only to make the builders happier about tests and should not
be needed.  This also pushes the condition variable setting to after the
watch is actually established (which was the source of the original race
condition, but would normally succeed as the thread shouldn't get put to
sleep immediately on the trigger of the condition variable).

This also was pretested on the chromium builders:
https://ci.chromium.org/ui/p/chromium/builders/try/win_upload_clang/1612/overview.
2021-06-19 09:19:52 -07:00
Nico Weber fb32de9e97 Re-Revert "DirectoryWatcher: add an implementation for Windows"
This reverts commit 76f1baa787.

Also reverts 2 follow-ups:

1. Revert "DirectoryWatcher: also wait for the notifier thread"
   This reverts commit 527a1821e6.

2. Revert "DirectoryWatcher: close a possible window of race on Windows"
   This reverts commit a6948da86a.

Makes tests hang, see comments on https://reviews.llvm.org/D88666
2021-06-18 18:51:41 -04:00
Saleem Abdulrasool a6948da86a DirectoryWatcher: close a possible window of race on Windows
The initial scan occurring before the watcher is ready allows a race
condition where a change occurs before the initial scan completes.
Ensure that we wait for the watcher to begin executing the initial scan.

Addresses some feedback from Adrian McCarthy in post-commit review.
2021-06-15 09:15:17 -07:00
Saleem Abdulrasool 527a1821e6 DirectoryWatcher: also wait for the notifier thread
Ultimately the DirectoryWatcher is not ready until the notifier thread
is also active.  Failure to wait for the notifier thread may result in
loss of events.  While this is not catastrophic in practice, the tests
are sensitive to this as depending on the thread scheduler, the thread
may fail to being execution before the operations are completed by the
fixture.  Running this in a tight loop shows no regressions locally as
previously, but this failure mode was been sighted once on a builder.
2021-06-13 10:58:55 -07:00
Saleem Abdulrasool 76f1baa787 Revert "Revert "DirectoryWatcher: add an implementation for Windows""
This reverts commit 0ec1cf13f2.

Restore the implementation with some minor tweaks:
- Use std::unique_ptr for the path instead of std::vector
  * Stylistic improvement as the buffer is already heap allocated, this
    just makes it clearer.
- Correct the notification buffer allocation size
  * Memory usage fix: we were allocating 4x the computed size
- Correct the passing of the buffer size to RDC
  * Memory usage fix: we were reporting 1/4th of the size
- Convert the operation event to auto-reset
  * Bug Fix: we never reset the event
- Remove `FILE_NOTIFY_CHANGE_LAST_ACCESS` from RDC events
  * Memory usage fix: we never needed this notification
- Fold events for the notification action
  * Stylistic improvement to be clear how the events map
- Update comment
  * Stylistic improvement to be clear what the RAII controls
- Fix the race condition that was uncovered previously
  * We would return from the construction before the watcher thread
    began execution.  The test would then proceed to begin execution,
    and we would miss the initial notifications.  We now ensure that the
    watcher thread is initialized before we return.  This ensures that
    we do not miss the initial notifications.

Running the test on a SSD was able to uncover the access pattern.  This
now seems to pass reliably where it was previously flaky locally.
2021-06-12 09:27:44 -07:00
Simon Pilgrim 72390f0c28 DirectoryWatcher-linux.cpp - add missing implicit MathExtras.h header dependency. NFCI. 2021-06-06 09:40:20 +01:00
Reid Kleckner d2ed9d6b7e Revert "ADT: Migrate users of AlignedCharArrayUnion to std::aligned_union_t, NFC"
We determined that the MSVC implementation of std::aligned* isn't suited
to our needs. It doesn't support 16 byte alignment or higher, and it
doesn't really guarantee 8 byte alignment. See
https://github.com/microsoft/STL/issues/1533

Also reverts "ADT: Change AlignedCharArrayUnion to an alias of std::aligned_union_t, NFC"

Also reverts "ADT: Remove AlignedCharArrayUnion, NFC" to bring back
AlignedCharArrayUnion.

This reverts commit 4d8bf870a8.

This reverts commit d10f9863a5.

This reverts commit 4b5dc150b9.
2020-12-14 17:04:06 -08:00
Duncan P. N. Exon Smith d10f9863a5 ADT: Migrate users of AlignedCharArrayUnion to std::aligned_union_t, NFC
Prepare to delete `AlignedCharArrayUnion` by migrating its users over to
`std::aligned_union_t`.

I will delete `AlignedCharArrayUnion` and its tests in a follow-up
commit so that it's easier to revert in isolation in case some
downstream wants to keep using it.

Differential Revision: https://reviews.llvm.org/D92516
2020-12-04 12:34:49 -08:00
Reid Kleckner 0ec1cf13f2 Revert "DirectoryWatcher: add an implementation for Windows"
This reverts commit 5d74c43511.
The gtest tests appear to be flaky, and are failing in various places.
2020-10-13 12:35:22 -07:00
Saleem Abdulrasool 5d74c43511 DirectoryWatcher: add an implementation for Windows
This implements the directory watcher on Windows.  It does the most
naive thing for simplicity.  ReadDirectoryChangesW is used to monitor
the changes.  However, in order to support interruption, we must use
overlapped IO, which allows us to use the blocking, synchronous
mechanism.  We create a thread to post the notification to the consumer
to allow the monitoring to continue.  The two threads communicate via a
locked queue.

Differential Revision: https://reviews.llvm.org/D88666
Reviewed By: Adrian McCarthy
2020-10-09 20:55:57 +00:00
Vedant Kumar cfb4f8c5fb [DirectoryWatcher] Do not use FSEvents on non-macOS platforms
The FSEvents APIs are available on iOS6+: however, the DirectoryWatcher
code isn't wired up to really use FSEvents on embedded platforms.

I've duplicated code from DirectoryWatcher-not-implemented.cpp here and
used TargetConditionals instead of adding cmakery to check try_compile;
I couldn't get that to work properly.
2020-04-23 10:22:28 -07:00
Sven van Haastregt 665dcdacc0 Add missing newlines at EOF; NFC 2020-02-12 15:57:25 +00:00
Ben Langmuir 2ac0c4b46e [DirectoryWatcher] Fix misuse of FSEvents API and data race
I observed two bugs in the DirectoryWatcher on macOS

1. We were calling FSEventStreamStop and FSEventStreamInvalidate before
we called FSEventStreamStart and FSEventStreamSetDispatchQueue, if the
DirectoryWatcher was destroyed before the initial async work was done.
This violates the requirements of the FSEvents API.

2. Calls to Receiver could race between the initial work and the
invalidation during destruction.

The second issue is easier to see when using TSan.

Differential Revision: https://reviews.llvm.org/D74371

rdar://59215667
2020-02-11 09:25:38 -08:00
Jonas Devlieghere 43a1c80508 Fix another implicit conversion in the directory watcher 2020-01-28 15:28:22 -08:00
Jonas Devlieghere 00d834e087 Fix more implicit conversions 2020-01-28 15:19:27 -08:00
Jonas Devlieghere 2b3d49b610 [Clang] Migrate llvm::make_unique to std::make_unique
Now that we've moved to C++14, we no longer need the llvm::make_unique
implementation from STLExtras.h. This patch is a mechanical replacement
of (hopefully) all the llvm::make_unique instances across the monorepo.

Differential revision: https://reviews.llvm.org/D66259

llvm-svn: 368942
2019-08-14 23:04:18 +00:00
Jan Korous 9a13852eab [clang][DirectoryWatcher] Fix Windows stub after LLVM change
r367979 changed DirectoryWatcher::Create to return an llvm::Expected.
Adjust the Windows stub accordingly.

(upstreamed from github.com/apple/swift-clang)

llvm-svn: 368762
2019-08-13 22:39:50 +00:00
Jan Korous b724f3d4b3 [clang] DirectoryWatcher for Windows stubs (to fix build break).
This is just a code skeleton for DirectoryWatcher-windows.cpp so the
build on Windows stops breaking.

(upstreamed from github.com/apple/swift-clang)

llvm-svn: 368761
2019-08-13 22:39:26 +00:00
Benjamin Kramer 762bc3351f Remove LLVM mutexes from clang in favor of std::mutex
None of those need to be recursive mutexes. No functionality change
intended.

llvm-svn: 368173
2019-08-07 14:44:40 +00:00
Puyan Lotfi 1dcf216f9f [clang][DirectoryWatcher][NFC] Swapping asserts for llvm fatal_error in create
I also have replaced all the instances of
"auto DW = DirectoryWatcher::create" with
llvm::Expected<std::unique_ptr<DirectoryWatcher>> DW = DirectoryWatcher::create
to make it more clear that DirectoryWatcher::create is returning an Expected.

I've also allowed for logAllUnhandledErrors to consume errors in the case were
DirectoryWatcher::create produces them.

Differential Revision: https://reviews.llvm.org/D65829

llvm-svn: 368108
2019-08-06 23:25:34 +00:00
Shoaib Meenai fe08528c8e [DirectoryWatcher] Fix asserts Mac builds
Add a missing semicolon after an assert. Remove the period from the
assert message while I'm here, because we don't usually have those.

llvm-svn: 367984
2019-08-06 07:13:53 +00:00
Puyan Lotfi ef74924fc7 [clang][DirectoryWatcher] Adding llvm::Expected error handling to create.
Prior to this patch Unix style errno error reporting from the inotify layer was
used by DirectoryWatcher::create to simply return a nullptr on error. This
would generally be ok, except that in LLVM we have much more robust error
reporting through the facilities of llvm::Expected.

The other critical thing I stumbled across was that the unit tests for
DirectoryWatcher were not failing abruptly when inotify_init() was reporting an
error, but would continue with the testing and eventually hit a deadlock in a
pathological machine state (ie in the unit test, the return nullptr on ::create
was ignored).

Generally this pathological state never happens on any build bot, so it is
totally understandable that it was overlooked, but on a Linux desktop running
a dubious desktop environment (which I will not name) there is a chance that
said desktop environment could use up enough inotify instances to exceed the
user's limit. These are the conditions that led me to hit the deadlock I am
addressing in this patch with more robust error handling.

With the new llvm::Expected error handling when your system runs out of inotify
instances for your user, the unit test will be forced to handle the error or
crash and report the issue to the user instead of weirdly deadlocking on a
condition variable wait.

Differential Revision: https://reviews.llvm.org/D65704

llvm-svn: 367979
2019-08-06 05:12:23 +00:00
Jan Korous 57f4bacf65 [DirectoryWatcher][linux] Fix build for older kernels
Apparently kernel support for IN_EXCL_UNLINK in inotify_add_watch() doesn't imply it's defined in sys/inotify.h.

https://bugs.llvm.org/show_bug.cgi?id=42824

llvm-svn: 367906
2019-08-05 18:44:07 +00:00
Jan Korous 9debb024d4 [DirectoryWatcher] Relax assumption to prevent test flakiness
llvm-svn: 367632
2019-08-01 23:24:30 +00:00
JF Bastien d9e55fa521 Fix Linux build
r367274 broke it

llvm-svn: 367276
2019-07-29 23:28:44 +00:00
JF Bastien ac8686205b [NFC] avoid AlignedCharArray in clang
As discussed in D65249, don't use AlignedCharArray or std::aligned_storage. Just use alignas(X) char Buf[Size];. This will allow me to remove AlignedCharArray entirely, and works on the current minimum version of Visual Studio.

llvm-svn: 367274
2019-07-29 23:12:48 +00:00
Jan Korous 60a0d49e77 [DirectoryWatcher][linux] Fix for older kernels
IN_EXCL_UNLINK exists since Linux 2.6.36

Differential Revision: https://reviews.llvm.org/D64764

llvm-svn: 366152
2019-07-15 23:14:00 +00:00
Jan Korous 000ba715dd [DirectoryWatcher][NFC] Silence warnings in release build
llvm-svn: 365968
2019-07-12 22:25:17 +00:00
Jan Korous ec2abbafda [DirectoryWatcher][linux] Fix use of uninitialized value
llvm-svn: 365966
2019-07-12 22:11:43 +00:00
Jan Korous 77dd8a7928 Reland [clang] DirectoryWatcher
This reverts commit f561227d13.

- DirectoryWatcher
- Fix the build for platforms that don't have DW implementated.
- Fix the threading dependencies (thanks to compnerd).

llvm-svn: 365954
2019-07-12 20:34:10 +00:00
Jan Korous f561227d13 Revert "Reland [clang] DirectoryWatcher"
This reverts commit fdcb7f47e7.

llvm-svn: 365948
2019-07-12 19:54:36 +00:00
Jan Korous fdcb7f47e7 Reland [clang] DirectoryWatcher
This reverts commit abce8c457d.

+ Fix the build for platforms that don't have DW implementated.

llvm-svn: 365947
2019-07-12 19:47:55 +00:00
Reid Kleckner abce8c457d Revert [clang] DirectoryWatcher
This reverts r365574 (git commit 31babea94a)

llvm-svn: 365581
2019-07-09 23:22:01 +00:00
Jan Korous 31babea94a [clang] DirectoryWatcher
Asynchronously monitors specified directory for changes and passes notifications to provided callback.

Dependency for index-while-building.

Differential Revision: https://reviews.llvm.org/D58418

llvm-svn: 365574
2019-07-09 22:44:48 +00:00