We rely on one variable _dmon.modify_watches shared between thread to
ensure that we don't lock with the dmon polling thread waiting indefinitely
and helding a lock.
To ensure that the polling thread sees modifications done to 'modify_watches'
we use an additional mutex that act as a memory barrier.
Evolve the rule for directory in ignore_files to be more natural
and easy to understand.
When a final '/' or '/$' is found we consider the pattern to match
a directory and the pattern is not modifed. In turns, is used, before
matching a directory's name a final '/' is appended to its name
before checking if it matches the pattern.
With the previous rule a final '/' in the pattern meant also a directory
but the '/' was removed from the pattern.
When a user's or project's module configuration file is changed we
make sure that the config.plugins fields are all restored so that
all plugins already loaded can continue to work.
Should fix commit bb12f085f3.
When taking the critical section we should always send the
event to wakeup the events thread. In addition use
TryEnterCriticalSection to send the event only if needed
reducing the number of spurious events sent.
Avoid waiting with a finite timeout and wait indefinitely in
dmon thread. When we need to unwatch we send a signal to a special
event meant to wakeup the waiting thread.
Some asserts are placed in case that can effectively occur
so we remove the assertion and we return false. In turn we
adapt the logic accordingly so when false is returned to add
a watch we do not open that directory.
Works correctly and the logic seems sound even if somewhat quirky.
`^%.` match any file of directory whose basename begins with a dot.
`^/node_modules$/"` match a directory named `node_modules` at the project's root.
Note that the final '/' needs to be at the end. The '/' after the '^' needs to be there to trigger
a match of the full path filename so we are sure it is at the root.
PROBLEM: the '/' to trigger full path match could be in a pattern's special expression like:
[^/]
`^%.git$/` match any directory name '.git' anywhere in the project.
`^/%.git$/` match a directory named '.git' only at the project's root.
`^/subprojects/.+/` match any directory in a top-level folder named "subprojects".
`^/build/` match any top level directory whose name begins with "build"
PROBLEM: may be surprising, one may expects it matches only a directory named 'build'. It actually acts like
it was `^/build.*/`.