Commit 667f51f
committed
fix: Refactor DConfig wrapper class generation for thread safety and lifecycle management
Problem:
- Single-threaded design with weak state machine (Invalid -> Succeed/Failed)
- No proper handling of object destruction during initialization
- Signal emissions in worker thread context (incorrect thread context)
- Fragile destructor unable to handle all cleanup scenarios
Solution:
1. Introduce Data layer separation (TreelandUserConfigData + TreelandUserConfig)
- Clear separation between internal data management and public API
- Enables safer object lifecycle management
2. Enhance state machine (3-state -> 5-state model)
- Add Initializing and Destroyed states
- Use atomic CAS operations for thread-safe state transitions
- States: Invalid -> Initializing -> (Succeed | Failed | Destroyed)
3. Improve async initialization and cleanup
- Use QPointer for safe backref checks (prevent use-after-free)
- Support 4 destruction paths: normal/failed/quick/mid-initialization
- Atomic state transitions with proper signal emission guards
4. Separate thread responsibilities
- updateValue(): Worker thread reads config values
- updateProperty(): Main thread updates properties and emits signals
- Use QMetaObject::invokeMethod for correct thread context
Improvements:
- Thread safety: Complete atomic operations coverage
- Memory safety: QPointer guards prevent dangling pointers
- Code clarity: Layered architecture with clear responsibilities
- Backward compatibility: API unchanged1 parent 52314ed commit 667f51f
1 file changed
+351
-259
lines changed
0 commit comments