|
34 | 34 |
|
35 | 35 | @resumable function (prot::CutoffProt)() |
36 | 36 | reg = prot.net[prot.node] |
| 37 | +<<<<<<< HEAD |
37 | 38 | while true |
38 | 39 | for slot in reg # TODO these should be done in parallel, otherwise we will be waiting on each slot, greatly slowing down the cutoffs |
39 | 40 | islocked(slot) && continue |
|
74 | 75 | else |
75 | 76 | @yield timeout(prot.sim, prot.period::Float64) |
76 | 77 | end |
| 78 | +======= |
| 79 | + for slot in reg |
| 80 | + @process per_slot_cutoff(prot.sim, slot, prot) |
| 81 | + end |
| 82 | +end |
| 83 | + |
| 84 | +@resumable function per_slot_cutoff(sim, slot::RegRef, prot::CutoffProt) |
| 85 | + empty_query = false |
| 86 | + while true |
| 87 | + if empty_query |
| 88 | + if isnothing(prot.period) |
| 89 | + @yield onchange_tag(slot) # TODO this should be just for the slot, not for the whole register |
| 90 | + else |
| 91 | + @yield timeout(prot.sim, prot.period::Float64) |
| 92 | + end |
| 93 | + end |
| 94 | + @yield lock(slot) |
| 95 | + info = query(slot, EntanglementCounterpart, ❓, ❓) |
| 96 | + if isnothing(info) |
| 97 | + empty_query = true |
| 98 | + unlock(slot) |
| 99 | + continue |
| 100 | + end |
| 101 | + println("$(now(sim)) $slot info $info") |
| 102 | + |
| 103 | + if now(prot.sim) - info.time > prot.retention_time |
| 104 | + untag!(slot, info.id) |
| 105 | + traceout!(slot) |
| 106 | + println("$(now(sim)) $slot traced out") |
| 107 | + msg = Tag(EntanglementDelete, prot.node, slot.idx, info.tag[2], info.tag[3]) |
| 108 | + tag!(slot, msg) |
| 109 | + (prot.announce) && put!(channel(prot.net, prot.node=>msg[4]; permit_forward=true), msg) |
| 110 | + @debug "CutoffProt @$(prot.node): Send message to $(msg[4]) | message=`$msg` | time=$(now(prot.sim))" |
| 111 | + end |
| 112 | + |
| 113 | + # TODO the tag deletions below are not necessary when announce=true and EntanglementTracker is running on other nodes. Verify the veracity of that statement, make tests for both cases, and document. |
| 114 | + |
| 115 | + # delete old history tags |
| 116 | + info = query(slot, EntanglementHistory, ❓, ❓, ❓, ❓, ❓;filo=false) # TODO we should have a warning if `queryall` returns more than one result -- what does it even mean to have multiple history tags here |
| 117 | + if !isnothing(info) && now(prot.sim) - info.time > prot.retention_time |
| 118 | + untag!(slot, info.id) |
| 119 | + end |
| 120 | + |
| 121 | + # delete old EntanglementDelete tags |
| 122 | + # TODO Why do we have separate entanglementhistory and entanglementupdate but we have only a single entanglementdelete that serves both roles? We should probably have both be pairs of tags, for consistency and ease of reasoning |
| 123 | + info = query(slot, EntanglementDelete, prot.node, slot.idx , ❓, ❓) # TODO we should have a warning if `queryall` returns more than one result -- what does it even mean to have multiple delete tags here |
| 124 | + if !isnothing(info) && now(prot.sim) - info.time > prot.retention_time |
| 125 | + untag!(slot, info.id) |
| 126 | + end |
| 127 | + |
| 128 | + unlock(slot) |
| 129 | +>>>>>>> e5a26b4d (first round of fixes to cutoff) |
77 | 130 | end |
78 | 131 | end |
0 commit comments