kicad/pcbnew/connectivity
Jon Evans 1e33928b96 Fix issues with zone filling connectivity locking
Two issues found with the locking system used to prevent access to
stale connectivity data during the zone fill process:

1) a std::mutex has undefined behavior if you try to use it to guard
against access from the same thread.  Because of the use of wx event
loops (and coroutines) it is entirely possible, and in some situations
inevitable, that the same thread will try to redraw the ratsnest in the
middle of zone refilling.

2) The mutex was only guarding the ZONE_FILLER::Fill method, but the callers
of that method also do connectivity updates as part of the COMMIT::Push.
Redrawing the ratsnest after the Fill but before the Push will result in
stale connectivity pointers to zone filled areas.

Fixed (1) by switching to a trivial spinlock implementation.  Spinlocks would
generally not be desirable if the contention for the connectivity data crossed
thread boundaries, but at the moment I believe it's guaranteed that the reads
and writes to connectivity that are guarded by this lock happen from the main
UI thread.  The writes are also quite rare compared to reads, and reads are
generally fast, so I'm not really worried about the UI thread spinning for any
real amount of time.

Fixed (2) by moving the locking location up to the call sites of
ZONE_FILLER::Fill.

This issue was quite difficult to reproduce, but I found a fairly reliable way:
It only happens (for me) on Windows, MSYS2 build, with wxWidgets 3.0
It also only happens if I restrict PcbNew to use 2 CPU cores.
With those conditions, I can reproduce the issue described in #6471 by
repeatedly editing a zone properties and changing its net.  The crash is
especially easy to trigger if you press some keys (such as 'e' for edit)
while the progress dialog is displayed.  It's easiest to do this in a debug
build as the slower KiCad is running, the bigger the window is to trigger this
bug.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/6471
Fixes https://gitlab.com/kicad/code/kicad/-/issues/7048
2021-01-18 13:22:12 -05:00
..
CMakeLists.txt pcb_new: CONNECTIVITY_DATA now keeps a cache of DRC from-tos 2020-09-27 16:45:46 +02:00
connectivity_algo.cpp More consistent naming. 2020-12-08 13:05:39 +00:00
connectivity_algo.h Remove some "class_" prefixes from files. 2020-11-13 15:16:23 +00:00
connectivity_data.cpp DRC: Fix a incorrect message and marker position when testing dangling vias. 2021-01-10 10:21:24 +01:00
connectivity_data.h Fix issues with zone filling connectivity locking 2021-01-18 13:22:12 -05:00
connectivity_items.cpp Implement free vias fully 2020-12-20 16:29:50 -05:00
connectivity_items.h Naming conventions. 2020-11-14 18:26:03 +00:00
connectivity_rtree.h Add more consts all over the place 2020-10-27 11:03:35 +00:00
from_to_cache.cpp MODULE -> FOOTPRINT. 2020-11-13 16:04:03 +00:00
from_to_cache.h D_PAD -> PAD. 2020-11-13 15:16:24 +00:00