kicad/pcbnew/tools
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
..
board_editor_control.cpp Prevent locking items in footprint editor 2021-01-11 11:23:26 -08:00
board_editor_control.h Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
board_inspection_tool.cpp Notify appearance panel when net is (un)hidden by board inspection tool 2021-01-14 17:22:41 +00:00
board_inspection_tool.h SNR. 2021-01-01 23:17:49 +00:00
board_reannotate_tool.cpp Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
board_reannotate_tool.h Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
convert_tool.cpp Don't warn on locked conversion 2021-01-08 16:49:47 -08:00
convert_tool.h Add conversion of circles to zones and enable in footprint editor. 2021-01-06 17:21:49 +00:00
drawing_tool.cpp Push shared parts of GRID_HELPERs into common. 2021-01-16 23:18:10 +00:00
drawing_tool.h A bit of "module" erradication, nameing conventions, and formatting. 2020-11-14 21:21:54 +00:00
drc_tool.cpp Be more targetted on when we load DRC Rules for better performance. 2021-01-01 23:17:49 +00:00
drc_tool.h Make prev/next marker work reliably on all platforms. 2020-12-01 22:37:07 +00:00
edit_tool.cpp Tidy up context menus a bit 2021-01-17 22:42:03 +00:00
edit_tool.h Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
footprint_editor_control.cpp Tidy up context menus a bit 2021-01-17 22:42:03 +00:00
footprint_editor_control.h Naming consistency. 2020-12-25 16:59:41 +00:00
global_edit_tool.cpp Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
global_edit_tool.h Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
group_tool.cpp Give GROUP_PROPERTIES_DIALOG its own files. 2020-12-29 12:41:24 +00:00
group_tool.h Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
pad_tool.cpp Give the pad placement tool a context menu. 2021-01-15 00:52:03 +00:00
pad_tool.h A bit of "module" erradication, nameing conventions, and formatting. 2020-11-14 21:21:54 +00:00
pcb_actions.cpp Push shared parts of GRID_HELPERs into common. 2021-01-16 23:18:10 +00:00
pcb_actions.h Re-factor boundary/courtyard checker error handling. 2020-11-21 20:57:35 +00:00
pcb_bright_box.cpp Remove some "class_" prefixes from files. 2020-11-13 15:16:23 +00:00
pcb_bright_box.h Comment-only changes 2020-01-10 16:43:01 -08:00
pcb_control.cpp Improve SNR and formatting. 2020-12-24 10:36:29 +00:00
pcb_control.h Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
pcb_editor_conditions.cpp Remove some "class_" prefixes from files. 2020-11-13 15:16:23 +00:00
pcb_editor_conditions.h Nip some common.h from headers 2020-10-24 08:28:03 -04:00
pcb_grid_helper.cpp Push shared parts of GRID_HELPERs into common. 2021-01-16 23:18:10 +00:00
pcb_grid_helper.h Push shared parts of GRID_HELPERs into common. 2021-01-16 23:18:10 +00:00
pcb_picker_tool.cpp Push shared parts of GRID_HELPERs into common. 2021-01-16 23:18:10 +00:00
pcb_picker_tool.h Don't use snapping for a selection interaction 2020-12-28 17:26:39 -05:00
pcb_point_editor.cpp Push shared parts of GRID_HELPERs into common. 2021-01-16 23:18:10 +00:00
pcb_point_editor.h Push shared parts of GRID_HELPERs into common. 2021-01-16 23:18:10 +00:00
pcb_selection.cpp Fix a bunch of issues with group selection and highlighting. 2020-12-29 12:41:24 +00:00
pcb_selection.h Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
pcb_selection_conditions.cpp Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
pcb_selection_conditions.h Naming conventions. 2020-11-14 18:26:03 +00:00
pcb_selection_tool.cpp Special case via area generation. 2021-01-14 12:48:44 +00:00
pcb_selection_tool.h Special case via area generation. 2021-01-14 12:48:44 +00:00
pcb_tool_base.cpp Give the pad placement tool a context menu. 2021-01-15 00:52:03 +00:00
pcb_tool_base.h Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
pcb_viewer_tools.cpp Push shared parts of GRID_HELPERs into common. 2021-01-16 23:18:10 +00:00
pcb_viewer_tools.h A bit of "module" erradication, nameing conventions, and formatting. 2020-11-14 21:21:54 +00:00
placement_tool.cpp Prevent locking items in footprint editor 2021-01-11 11:23:26 -08:00
placement_tool.h Don't apply "normal" locking strategy to alignment options. 2020-12-27 15:02:25 +00:00
position_relative_tool.cpp Position relative: store discarded pad for use as the selection anchor 2021-01-17 14:25:52 -05:00
position_relative_tool.h Position relative: store discarded pad for use as the selection anchor 2021-01-17 14:25:52 -05:00
tool_event_utils.cpp More modern toolset context menu work. 2019-05-05 17:12:59 +01:00
tool_event_utils.h More modern toolset context menu work. 2019-05-05 17:12:59 +01:00
zone_create_helper.cpp Fix issues with zone filling connectivity locking 2021-01-18 13:22:12 -05:00
zone_create_helper.h Update some classnames including archaic zone names. 2020-11-12 10:31:25 +00:00
zone_filler_tool.cpp Fix issues with zone filling connectivity locking 2021-01-18 13:22:12 -05:00
zone_filler_tool.h Remove redundant clearances from DRC dialog. Fold progress bar in. 2020-09-16 16:06:29 +01:00