summaryrefslogtreecommitdiff
path: root/map65/libm65/npar_ptrs_mod.f90
diff options
context:
space:
mode:
authorChristoph Berg <myon@debian.org>2026-10-09 14:12:35 +0200
committerChristoph Berg <myon@debian.org>2026-10-09 14:12:35 +0200
commitffc62c792c9a5196cb4ce7a353287dfe20db6524 (patch)
tree1269efa852935b183daae4bb33a58d1b4d2ffb53 /map65/libm65/npar_ptrs_mod.f90
parent059831534c7e884f0a607ed86b582fd00d821731 (diff)
New upstream version 3.3.0~beta1+dfsgupstream/3.3.0_beta1+dfsg
Diffstat (limited to 'map65/libm65/npar_ptrs_mod.f90')
-rw-r--r--map65/libm65/npar_ptrs_mod.f9059
1 files changed, 50 insertions, 9 deletions
diff --git a/map65/libm65/npar_ptrs_mod.f90 b/map65/libm65/npar_ptrs_mod.f90
index f33a92fc..10c9b904 100644
--- a/map65/libm65/npar_ptrs_mod.f90
+++ b/map65/libm65/npar_ptrs_mod.f90
@@ -40,7 +40,56 @@ module npar_ptrs_mod
character(len=20) :: datetime = ''
end type
- ! GUI setters prepare draft; only the decoder changes active after claiming a request.
+ ! ---------------------------------------------------------------------------
+ ! Decode parameters: draft vs. active
+ !
+ ! Two copies of decode_parameters exist, and which one you touch matters.
+ !
+ ! draft Owned by the GUI thread. Every set_xxx()/get_xxx() bind(C)
+ ! routine in this module reads or writes draft, under
+ ! lock_decode_requests(). It holds the *pending* GUI state, not
+ ! necessarily what the decoder is using right now.
+ !
+ ! active Owned by the decode thread. The module pointers below (nkeep,
+ ! ntimeout, mycall, ...) alias fields of active, so Fortran decode
+ ! code that says "ntimeout" is reading active%ntimeout.
+ !
+ ! Flow:
+ ! MainWindow::decode() -> set_xxx() writes draft
+ ! publish_decode_request() copies draft into a queued request (forcing
+ ! newdat = 1 in that copy) and clears
+ ! draft%manualDecodeFlag
+ ! claim_decode_request() copies the oldest request into active; an
+ ! automatic live request whose input generation
+ ! is out of date is marked expired, and run_m65
+ ! skips it (<DecodeSkipped>)
+ ! initialize_decode_parameters() copies draft into active once, at startup
+ ! The decoder then sees a consistent snapshot for the whole pass, even if
+ ! the GUI changes draft meanwhile.
+ !
+ ! Why a lock alone is not enough: a decode pass runs for many seconds and
+ ! reads its parameters throughout. The lock only protects the instant of a
+ ! write, so if setters wrote the decoder's own variables directly, a GUI
+ ! change mid-pass would still alter values partway through the decode. The
+ ! draft/active copy is what freezes the parameters for a pass and lets
+ ! requests queue; the lock keeps publish_decode_request from copying a
+ ! half-written draft.
+ !
+ ! Rules:
+ ! * C++ callers: a get_xxx() returns draft, i.e. the pending GUI value,
+ ! not the value the running decode is using.
+ ! * A parameter only reaches the decoder if the GUI writes it to draft
+ ! before a request is published. Setting it once and never re-pushing
+ ! works only if nothing else overwrites it (decode() currently re-pushes
+ ! most values every cycle).
+ ! * Fortran code may write active fields only for state it owns (e.g.
+ ! manualDecodeFlag = 0, nkeep = ...). Such writes do NOT flow back to
+ ! draft, so the next published request will carry draft's old value.
+ ! If a value must persist across requests, change it in draft too.
+ ! * Never add a second variable for the same setting (cf. the old
+ ! map65RxLog vs. nrxlog bug, where the setter wrote one variable and the
+ ! decoder read the other).
+ ! ---------------------------------------------------------------------------
type(decode_parameters), target, save :: active
type(decode_parameters), save :: draft
type :: decode_request
@@ -475,14 +524,6 @@ contains
subroutine set_map65RxLog(val) bind(C, name="set_map65RxLog")
use iso_c_binding
integer(c_int), value :: val
- ! map65RxLog is read back by get_map65RxLog() for debug logging only.
- ! nrxlog is the variable m65c()/decode0.f90 actually check (iand bits
- ! 1/2/4/8) to write the date header, erase map65_rx.log, clear the
- ! decode-history file on Erase, and force manual dPhi. Before this fix
- ! nrxlog was never assigned anywhere, so all four of those flag bits
- ! were permanently dead -- e.g. Erase Band Map and Messages never
- ! actually cleared unit 26, so the next display() cycle just replayed
- ! the full decode history back into the Messages window.
call lock_decode_requests()
draft%map65RxLog = val
draft%nrxlog = val