Commit 0860ade
committed
Document lock acquisition sites and strong->weak GCHandle swap
Comment-only changes. Adds inline notes at lock acquisitions where the
"why" is not obvious from the field declaration alone:
- ClassDerivedObject.Reset / GetModuleBuilder: explain that both
builder caches must update atomically and that DefineDynamicAssembly
/ DefineDynamicModule produce duplicates under contention.
- TypeManager.GetType: note that CreateType + cache write must be
atomic.
- ReflectedClrType.GetOrCreate: cross-file lock; mention it also
serialises ClassManager.cache and TypeManager._slotsHolders writes.
- Runtime.ResetPyMembers: explain the snapshot-then-dispose pattern
(Dispose() callbacks would deadlock if invoked under the lock).
Expands the strong->weak GCHandle swap in ClassDerivedObject.tp_dealloc
to spell out:
1. Why the PyObject is not freed at refcount 0 (C# wrapper may still
reference it; ToPython() resurrects via _Py_NewReference).
2. Why the handle is demoted to weak (lets the C# wrapper be GC'd; on
collection PyFinalize enqueues the real PyObject_GC_Del).
3. Why the swap uses Interlocked.Exchange (tp_clear may race on the
same slot under FT / finalizer thread; without atomic claim both
threads could observe and double-free the same handle).1 parent 92072bd commit 0860ade
4 files changed
Lines changed: 24 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
414 | 414 | | |
415 | 415 | | |
416 | 416 | | |
| 417 | + | |
| 418 | + | |
417 | 419 | | |
418 | 420 | | |
419 | 421 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
46 | 48 | | |
47 | 49 | | |
48 | 50 | | |
| |||
83 | 85 | | |
84 | 86 | | |
85 | 87 | | |
86 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
87 | 103 | | |
88 | 104 | | |
89 | 105 | | |
| |||
678 | 694 | | |
679 | 695 | | |
680 | 696 | | |
| 697 | + | |
| 698 | + | |
681 | 699 | | |
682 | 700 | | |
683 | 701 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| |||
0 commit comments