Commit 9706d15
committed
Fix sd-bus thread-safety crash in Linux tray (#405)
sd-bus objects are not thread-safe, but the event-loop thread
(sd_bus_process) and the JVM threads driving the sni_tray_set_*/
sni_tray_item_* mutators (sd_bus_emit_*) accessed tray->bus with no
synchronization. Under frequent updates an emit races with an in-flight
sd_bus_process and trips 'Assertion !bus->current_slot ... Aborting'.
- Add a bus_lock mutex serializing all sd_bus_* access and the tray
state it touches: held across setup, each sd_bus_process batch and
teardown, and acquired by every public mutator.
- Defer user callbacks (click / menu) through a queue flushed by the
event loop after releasing bus_lock, so upcalls into Kotlin can
re-enter the mutators without deadlocking against the caller's lock.
- Add a standalone C concurrency regression test that aborts on the
old code and passes on the fixed code.1 parent 03cd59a commit 9706d15
3 files changed
Lines changed: 289 additions & 26 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
0 commit comments