kicad/pcbnew
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
..
autorouter Encourage use of full DRC for board & footprint malformed outlines. 2020-11-20 17:24:52 +00:00
board_stackup_manager Minor adjustments 2021-01-12 20:51:31 +00:00
connectivity Fix issues with zone filling connectivity locking 2021-01-18 13:22:12 -05:00
dialogs Clean up Text Properties dialog. 2021-01-18 15:20:15 +00:00
drc Make sure pad local clearances get in to m_worstClearance. 2021-01-13 12:37:20 +00:00
exporters Pcbnew, drill map: fix incorrect position of texts for small boards. 2021-01-14 18:52:04 +01:00
import_gfx Remove polyline 3d check added by previous fixes 2021-01-09 18:56:35 -05:00
microwave Move headers from common folders to appropriate include folders round 1. 2020-12-17 08:12:18 -05:00
netlist_reader Make sure we mark board-only-footprint nets as current. 2021-01-15 12:46:48 +00:00
plugins Fabmaster: fix MSVC build 2021-01-17 10:23:31 -05:00
python Remove ddr3_length_match.py 2020-11-20 08:10:53 +00:00
ratsnest Fix issues with zone filling connectivity locking 2021-01-18 13:22:12 -05:00
router Push shared parts of GRID_HELPERs into common. 2021-01-16 23:18:10 +00:00
specctra_import_export More consistent naming. 2020-12-08 13:05:39 +00:00
swig Fix compile error 2021-01-13 13:21:27 -08:00
tools Fix issues with zone filling connectivity locking 2021-01-18 13:22:12 -05:00
widgets Update local ratsnest state when toggling appearance control 2021-01-14 22:03:23 -05:00
CMakeLists.txt Push shared parts of GRID_HELPERs into common. 2021-01-16 23:18:10 +00:00
Doxyfile_python
Doxyfile_xml
action_plugin.cpp Mostly formatting cleanup but a few type-casting cleanups too. 2020-11-24 22:16:41 +00:00
action_plugin.h
array_creator.cpp MODULE -> FOOTPRINT. 2020-11-13 16:04:03 +00:00
array_creator.h Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
array_pad_name_provider.cpp MODULE -> FOOTPRINT. 2020-11-13 16:04:03 +00:00
array_pad_name_provider.h More cleanup of MODULE to see if it fixes SWIG error. 2020-11-13 21:07:36 +00:00
board.cpp Move title block fields to global availability in PCBNew. 2021-01-15 15:41:18 +00:00
board.h Add more const specifiers 2021-01-12 20:51:31 +00:00
board_commit.cpp Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
board_commit.h Formatting. 2020-11-29 20:00:16 +00:00
board_connected_item.cpp More consistent naming. 2020-12-08 13:05:39 +00:00
board_connected_item.h More consistent naming. 2020-12-08 13:05:39 +00:00
board_design_settings.cpp Factor in all clearance types when asking for worst clearance. 2021-01-01 00:31:36 +00:00
board_item.cpp Implement GetEffectiveShape() for PCB_TARGET_Ts. 2020-11-24 20:21:40 +00:00
board_item_container.h Add bulk add/remove mode flag to the BOARD_LISTENER 2020-12-07 22:04:13 -05:00
board_items_to_polygon_shape_transform.cpp More improvements to new selection disambiguation. 2020-11-29 14:02:46 +00:00
build_BOM_from_board.cpp Mostly formatting cleanup but a few type-casting cleanups too. 2020-11-24 22:16:41 +00:00
cleanup_item.cpp more cleanup about removing useless include 2020-10-02 14:51:11 +02:00
cleanup_item.h Finish exorcising the old DRC system. 2020-09-15 20:15:46 +01:00
collectors.cpp Use a sloppier hittest for the collector as well as the actual hittest. 2021-01-13 21:22:24 +00:00
collectors.h Use a sloppier hittest for the collector as well as the actual hittest. 2021-01-13 21:22:24 +00:00
convert_drawsegment_list_to_polygon.cpp Fix issues in ConvertOutlineToPolygon() related to S_POLYGON PCV_SHAPE 2021-01-11 17:05:44 +01:00
convert_drawsegment_list_to_polygon.h Separate polygonization error from chaining error. 2020-12-24 21:02:14 +00:00
cross-probing.cpp Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
dimension.cpp Clip the first segment in leaders 2021-01-14 00:10:41 +00:00
dimension.h Naming conventions. 2020-11-14 18:26:03 +00:00
edit.cpp Don't request a full frame refresh when editing text properties (stop apperance flickering) 2020-12-09 21:14:48 -05:00
edit_track_width.cpp Nets don't have properites; netclasses do. 2020-12-08 13:05:39 +00:00
edit_zone_helpers.cpp Fix issues with zone filling connectivity locking 2021-01-18 13:22:12 -05:00
files.cpp pcbnew: Add Fabmaster import 2021-01-16 14:28:33 -08:00
footprint.cpp Remove a few const_cast 2021-01-12 20:51:31 +00:00
footprint.h Move pad locking from footprint to pads. 2021-01-08 20:43:02 +00:00
footprint_edit_frame.cpp Push shared parts of GRID_HELPERs into common. 2021-01-16 23:18:10 +00:00
footprint_edit_frame.h Use color theme backgrounds in page previews. 2020-12-23 23:18:38 +00:00
footprint_editor_settings.cpp Fix graphics snapping in Footprint Editor. 2020-12-19 00:21:28 +00:00
footprint_editor_utils.cpp Simplify some error messages. 2020-12-18 00:30:26 +00:00
footprint_info_impl.cpp Use a temp file for saving the fp-info-cache for now 2020-12-10 23:07:49 -05:00
footprint_info_impl.h Replace wxTextFile for writing fp info cache 2020-12-10 21:34:40 -05:00
footprint_libraries_utils.cpp Clean up some more user messages. 2020-12-18 12:49:20 +00:00
footprint_preview_panel.cpp Remove multi-threading for footprint loading. 2020-12-21 22:03:24 +00:00
footprint_preview_panel.h Remove multi-threading for footprint loading. 2020-12-21 22:03:24 +00:00
footprint_tree_pane.cpp More Module -> Footprint and a bit of formatting cleanup. 2020-11-10 20:53:12 +00:00
footprint_tree_pane.h
footprint_viewer_frame.cpp Icons: general tweaks and pixel alignment 2021-01-11 23:31:25 +00:00
footprint_viewer_frame.h Use color theme backgrounds in page previews. 2020-12-23 23:18:38 +00:00
footprint_wizard.cpp
footprint_wizard.h MODULE -> FOOTPRINT. 2020-11-13 16:04:03 +00:00
footprint_wizard_frame.cpp Use color theme backgrounds in page previews. 2020-12-23 23:18:38 +00:00
footprint_wizard_frame.h Use color theme backgrounds in page previews. 2020-12-23 23:18:38 +00:00
footprint_wizard_frame_functions.cpp MODULE -> FOOTPRINT. 2020-11-13 16:04:03 +00:00
fp_shape.cpp CADSTAR PCB Archive Importer: Fix arc and filled shapes in footprints 2020-12-10 14:35:37 +00:00
fp_shape.h Move footprint shape offset/rotation stuff to the right place. 2020-11-15 21:04:12 +00:00
fp_text.cpp Resolve text variables in title blocks for outputing to netlist. 2021-01-17 16:24:22 +00:00
fp_text.h Minor adjustments 2021-01-12 20:51:31 +00:00
fp_tree_model_adapter.cpp Fix library tree behavior when duplicate project table entry is disabled. 2021-01-11 07:46:07 -05:00
fp_tree_model_adapter.h Formatting and naming conventions. 2020-11-07 18:50:30 +00:00
fp_tree_synchronizing_adapter.cpp Fix library tree behavior when duplicate project table entry is disabled. 2021-01-11 07:46:07 -05:00
fp_tree_synchronizing_adapter.h Formatting and naming conventions. 2020-11-07 18:50:30 +00:00
generate_footprint_info.cpp Fix issues in reporting netclasses. 2020-11-30 14:38:06 +00:00
generate_footprint_info.h
graphics_cleaner.cpp Mostly formatting cleanup but a few type-casting cleanups too. 2020-11-24 22:16:41 +00:00
graphics_cleaner.h MODULE -> FOOTPRINT. 2020-11-13 16:04:03 +00:00
grid_layer_box_helpers.cpp Remove some "class_" prefixes from files. 2020-11-13 15:16:23 +00:00
grid_layer_box_helpers.h Dismiss the layer selector grid combobox when it loses focus 2020-10-10 15:24:35 +01:00
initpcb.cpp More module -> footprint. 2020-11-13 15:16:24 +00:00
invoke_pcb_dialog.h MODULE -> FOOTPRINT. 2020-11-13 16:04:03 +00:00
io_mgr.cpp pcbnew: Add Fabmaster import 2021-01-16 14:28:33 -08:00
io_mgr.h pcbnew: Add Fabmaster import 2021-01-16 14:28:33 -08:00
kicad_clipboard.cpp Add optional project parameter to PCB plugin load method. 2020-12-18 10:40:51 -05:00
kicad_clipboard.h Add optional project parameter to PCB plugin load method. 2020-12-18 10:40:51 -05:00
load_select_footprint.cpp Formatting. 2021-01-09 13:47:24 +00:00
menubar_footprint_editor.cpp Icons: standardise `export_png` to match set 2020-12-24 01:02:03 +00:00
menubar_pcb_editor.cpp Icons: general tweaks and pixel alignment 2021-01-11 23:31:25 +00:00
netinfo.h More consistent naming. 2020-12-08 13:05:39 +00:00
netinfo_item.cpp Fix minor compil warnings. 2020-12-08 18:28:03 +01:00
netinfo_list.cpp More consistent naming. 2020-12-08 13:05:39 +00:00
pad.cpp Get rid of "drill" terminology when talking about finish hole size. 2021-01-11 13:49:43 +00:00
pad.h Performance enhancements. 2021-01-08 00:46:55 +00:00
pad_custom_shape_functions.cpp Performance enhancements. 2021-01-08 00:46:55 +00:00
pad_naming.cpp D_PAD -> PAD. 2020-11-13 15:16:24 +00:00
pad_naming.h D_PAD -> PAD. 2020-11-13 15:16:24 +00:00
pcb_base_edit_frame.cpp Use color theme backgrounds in page previews. 2020-12-23 23:18:38 +00:00
pcb_base_edit_frame.h Make sure SCH-related frames use the schematic worksheet color. 2020-12-25 16:59:41 +00:00
pcb_base_frame.cpp Use color theme backgrounds in page previews. 2020-12-23 23:18:38 +00:00
pcb_display_options.cpp ADDED: Control to only show ratsnest for visible layers 2020-09-07 16:43:43 -04:00
pcb_draw_panel_gal.cpp LAYER_PADS_TH is not a dependent layer 2021-01-07 20:12:31 -05:00
pcb_draw_panel_gal.h Remove common.h from more headers 2020-10-25 22:29:53 -04:00
pcb_edit_frame.cpp Push shared parts of GRID_HELPERs into common. 2021-01-16 23:18:10 +00:00
pcb_edit_frame.h Simplify layer pair indicator icon. 2021-01-04 19:19:55 +00:00
pcb_expr_evaluator.cpp Fix bone-headed error in rules optimization. 2021-01-12 12:46:51 +00:00
pcb_expr_evaluator.h Performance improvements for DRC rules. 2021-01-11 22:09:36 +00:00
pcb_group.cpp Don't dereference board groups in fp editor 2021-01-11 14:58:33 -08:00
pcb_layer_box_selector.cpp Remove some "class_" prefixes from files. 2020-11-13 15:16:23 +00:00
pcb_layer_box_selector.h
pcb_marker.cpp Don't put up double lock confirmation dialogs. 2020-12-15 22:34:24 +00:00
pcb_marker.h Make wxFindReplaceData argument const 2021-01-12 20:51:31 +00:00
pcb_origin_transforms.cpp Add more consts all over the place 2020-10-27 11:03:35 +00:00
pcb_origin_transforms.h Add more consts all over the place 2020-10-27 11:03:35 +00:00
pcb_painter.cpp Add margin to both sides to avoid drawing 0-poly 2021-01-09 13:05:58 -08:00
pcb_painter.h Improve SNR and formatting. 2020-12-24 10:36:29 +00:00
pcb_plot_params.cpp Save DXF plot params to file and remove some dead code. 2021-01-03 14:22:25 +00:00
pcb_plot_params.h Save DXF plot params to file and remove some dead code. 2021-01-03 14:22:25 +00:00
pcb_plot_params_parser.h
pcb_screen.cpp more cleanup about removing useless include 2020-10-02 14:51:11 +02:00
pcb_shape.cpp Use less-sophisticated arc editing math. 2021-01-16 20:46:14 +00:00
pcb_shape.h Use less-sophisticated arc editing math. 2021-01-16 20:46:14 +00:00
pcb_target.cpp PCB_TARGET: add missing GetMsgPanelInfo() virtual function. 2020-12-31 15:46:58 +01:00
pcb_target.h PCB_TARGET: add missing GetMsgPanelInfo() virtual function. 2020-12-31 15:46:58 +01:00
pcb_text.cpp One more attempt to fix flipping geometry. 2021-01-18 15:20:15 +00:00
pcb_text.h Make wxFindReplaceData argument const 2021-01-12 20:51:31 +00:00
pcb_view.cpp A groups children may also have children. 2021-01-09 13:47:24 +00:00
pcb_view.h Naming conventions. 2020-11-14 18:26:03 +00:00
pcbnew.cpp Fix the install location for vcpkg built python modules 2021-01-07 00:08:11 -05:00
pcbnew.h Minor code cleanup, step3: remove more useless include. 2020-10-01 18:28:12 +02:00
pcbnew.icns Update icon resource sets 2020-12-22 15:16:33 -08:00
pcbnew.rc Handle Windows manifests ourselves and add dpi awareness option 2020-10-10 19:08:23 +00:00
pcbnew_config.cpp Remember autotrack width setting 2021-01-06 20:11:32 -08:00
pcbnew_config.h
pcbnew_doc.icns Update icon resource sets 2020-12-22 15:16:33 -08:00
pcbnew_id.h Cleanup. Push more editing functions to toolset. 2020-11-10 20:14:26 +00:00
pcbnew_printout.cpp Make small drill marks size configurable via advanced config for both printing and plotting 2021-01-05 22:37:34 +00:00
pcbnew_printout.h D_PAD -> PAD. 2020-11-13 15:16:24 +00:00
pcbnew_settings.cpp Prevent locking items in footprint editor 2021-01-11 11:23:26 -08:00
pcbnew_settings.h Prevent locking items in footprint editor 2021-01-11 11:23:26 -08:00
pcbplot.cpp Resolve text variables in title blocks for outputing to netlist. 2021-01-17 16:24:22 +00:00
pcbplot.h Make small drill marks size configurable via advanced config for both printing and plotting 2021-01-05 22:37:34 +00:00
plot_board_layers.cpp Make small drill marks size configurable via advanced config for both printing and plotting 2021-01-05 22:37:34 +00:00
plot_brditems_plotter.cpp Make small drill marks size configurable via advanced config for both printing and plotting 2021-01-05 22:37:34 +00:00
plotcontroller.h
plugin.cpp Add optional project parameter to PCB plugin load method. 2020-12-18 10:40:51 -05:00
sel_layer.cpp Better sizing for some conditional dialogs. 2021-01-07 01:27:12 +00:00
text_mod_grid_table.cpp Mostly formatting cleanup but a few type-casting cleanups too. 2020-11-24 22:16:41 +00:00
text_mod_grid_table.h MODULE -> FOOTPRINT. 2020-11-13 16:04:03 +00:00
toolbars_footprint_editor.cpp Consistency for gerbview toolbar icons and some other icon tweaks. 2020-12-17 14:02:23 +00:00
toolbars_footprint_viewer.cpp Icons: fix incorrect icon in footprint browser 2021-01-04 01:44:02 +00:00
toolbars_pcb_editor.cpp Improve some tooltips. 2021-01-14 22:35:32 +00:00
track.cpp Fix a I18n issue: a string flagged as translatable cannot be empty. 2021-01-08 18:16:00 +01:00
track.h Implement locking for graphic shapes. 2021-01-07 17:39:18 +00:00
tracks_cleaner.cpp Consider tracks and vias together 2021-01-08 09:35:58 -08:00
tracks_cleaner.h Consider tracks and vias together 2021-01-08 09:35:58 -08:00
undo_redo.cpp Make distinction between PCBNew-wide tools and Board-specific tools. 2020-12-16 13:32:46 +00:00
zone.cpp Add more const specifiers 2021-01-12 20:51:31 +00:00
zone.h Add missing const to Matches 2021-01-12 20:51:32 +00:00
zone_filler.cpp Fix issues with zone filling connectivity locking 2021-01-18 13:22:12 -05:00
zone_filler.h Fix issues with zone filling connectivity locking 2021-01-18 13:22:12 -05:00
zone_settings.cpp Remove some "class_" prefixes from files. 2020-11-13 15:16:23 +00:00
zone_settings.h Update some classnames including archaic zone names. 2020-11-12 10:31:25 +00:00
zones.h Update some classnames including archaic zone names. 2020-11-12 10:31:25 +00:00
zones_functions_for_undo_redo.cpp Remove some "class_" prefixes from files. 2020-11-13 15:16:23 +00:00
zones_functions_for_undo_redo.h Convert UNDO_REDO_T to an enum class 2020-08-26 18:04:32 +00:00