| 2341 | } |
| 2342 | |
| 2343 | int64_t FileExpertSource::commit_flip() { |
| 2344 | int64_t n = 0; |
| 2345 | for (const Exchange& x : staged_) { |
| 2346 | const uint8_t* src = override_[x.out]; |
| 2347 | if (exchange_storage_.active()) { // STRATA_EXCHANGE_ROTATE: the same ownership transfer as commit_exchanges |
| 2348 | if (!exchange_storage_.commit(x.in, x.out, (size_t) x.q, src, (size_t) x.bytes)) { |
| 2349 | std::fprintf(stderr, "FileExpertSource: invalid exchange rotation commit; refusing corrupt residency\n"); |
| 2350 | std::abort(); |
| 2351 | } |
| 2352 | ++n; |
| 2353 | override_[x.out] = nullptr; |
| 2354 | continue; |
| 2355 | } |
| 2356 | const uint64_t at = complement_offsets_[x.in]; |
| 2357 | // the same test as commit_copies: an exchange whose bytes were copied is the one that flips |
| 2358 | if (src != nullptr && at != kNoComplement && at <= complement_bytes_ && x.bytes <= complement_bytes_ - at && |
| 2359 | complement_host_ != nullptr && detail::exchange_cache_complement(complement_offsets_, x.in, x.out)) |
| 2360 | ++n; |
| 2361 | override_[x.out] = nullptr; |
| 2362 | } |
| 2363 | staged_.clear(); |
| 2364 | exchanges_ += n; |
| 2365 | return n; |
| 2366 | } |
| 2367 | |
| 2368 | const uint8_t* FileExpertSource::resident_blob(int64_t layer, int64_t expert) const { |
| 2369 | if (!complement_ready_ || complement_host_ == nullptr || layer < 0 || expert < 0 || layer >= n_layers_ || |