1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-10-31 20:16:07 +00:00

Introduces flush_tracks to Drive, while switching its interface to using Track::Address and adjusting associated integer types.

This commit is contained in:
Thomas Harte
2017-10-06 21:45:12 -04:00
parent f623bff5c3
commit 97a2be71e3
29 changed files with 150 additions and 238 deletions

View File

@@ -6,11 +6,11 @@
// Copyright © 2017 Thomas Harte. All rights reserved.
//
template <typename T> unsigned int DiskImageHolder<T>::get_head_position_count() {
template <typename T> int DiskImageHolder<T>::get_head_position_count() {
return disk_image_.get_head_position_count();
}
template <typename T> unsigned int DiskImageHolder<T>::get_head_count() {
template <typename T> int DiskImageHolder<T>::get_head_count() {
return disk_image_.get_head_count();
}
@@ -18,28 +18,29 @@ template <typename T> bool DiskImageHolder<T>::get_is_read_only() {
return disk_image_.get_is_read_only();
}
template <typename T> void DiskImageHolder<T>::set_track_at_position(unsigned int head, unsigned int position, const std::shared_ptr<Track> &track) {
template <typename T> void DiskImageHolder<T>::flush_tracks() {
}
template <typename T> void DiskImageHolder<T>::set_track_at_position(Track::Address address, const std::shared_ptr<Track> &track) {
if(disk_image_.get_is_read_only()) return;
int address = get_id_for_track_at_position(head, position);
cached_tracks_[address] = track;
if(!update_queue_) update_queue_.reset(new Concurrency::AsyncTaskQueue);
std::shared_ptr<Track> track_copy(track->clone());
update_queue_->enqueue([this, head, position, track_copy] {
disk_image_.set_track_at_position(head, position, track_copy);
update_queue_->enqueue([this, address, track_copy] {
disk_image_.set_track_at_position(address, track_copy);
});
}
template <typename T> std::shared_ptr<Track> DiskImageHolder<T>::get_track_at_position(unsigned int head, unsigned int position) {
if(head >= get_head_count()) return nullptr;
if(position >= get_head_position_count()) return nullptr;
template <typename T> std::shared_ptr<Track> DiskImageHolder<T>::get_track_at_position(Track::Address address) {
if(address.head >= get_head_count()) return nullptr;
if(address.position >= get_head_position_count()) return nullptr;
int address = get_id_for_track_at_position(head, position);
std::map<int, std::shared_ptr<Track>>::iterator cached_track = cached_tracks_.find(address);
auto cached_track = cached_tracks_.find(address);
if(cached_track != cached_tracks_.end()) return cached_track->second;
std::shared_ptr<Track> track = disk_image_.get_track_at_position(head, position);
std::shared_ptr<Track> track = disk_image_.get_track_at_position(address);
if(!track) return nullptr;
cached_tracks_[address] = track;
return track;