计算属性自动检查
This commit is contained in:
@@ -500,21 +500,25 @@ device.with_all_writable_locked([&](auto& guard) {
|
||||
Synchronized computed property 接收 read view:
|
||||
|
||||
```cpp
|
||||
computed_property<Device, int>([](const auto& view) {
|
||||
computed_property<Device, int>(depends_on<&Device::min_speed, &Device::max_speed>, [](const auto& view) {
|
||||
return view.template get<&Device::max_speed>() - view.template get<&Device::min_speed>();
|
||||
}, key<"speed_span">)
|
||||
```
|
||||
|
||||
如果 writable dependency 需要同一快照,应共享 computed synchronization domain:
|
||||
`depends_on<...>` 把 dependency 变成 Schema 的显式结构事实。也可以通过 `depends_on_keys<"a", "b">` 按 key 声明。Computed view 只能读取已声明的直接 dependency。
|
||||
|
||||
如果 writable dependency 需要同一快照,只需要让这些 writable dependency 共享 synchronization domain:
|
||||
|
||||
```cpp
|
||||
synchronization(
|
||||
sync_all_independent,
|
||||
sync_group("speed", "min_speed", "max_speed", "speed_span")
|
||||
sync_group("speed", "min_speed", "max_speed")
|
||||
)
|
||||
```
|
||||
|
||||
Read-only stored dependency 可以直接通过 computed view 读取,不需要加入 lock slot,因为它没有 managed writer。
|
||||
Computed Property 自身不要加入 synchronization rule。它的读取 slot 根据 dependency graph 自动推导;如果需要同步的 dependency 不在同一个 domain,Schema/实例 synchronization topology 会被拒绝。Read-only stored dependency 不需要 lock slot。
|
||||
|
||||
Schema 可通过 `schema_property_dependency_indices<Schema, Index>()` 读取某个 Property 的直接 dependency index。
|
||||
|
||||
## 21. Trusted Accessor Property
|
||||
|
||||
|
||||
Reference in New Issue
Block a user