1
0
mirror of https://github.com/TomHarte/CLK.git synced 2024-07-06 01:28:57 +00:00

Ensures lifetime-linked track flushing without relying on virtual calls within a destructor.

This commit is contained in:
Thomas Harte 2017-10-07 19:14:18 -04:00
parent 53b99ea248
commit b37787a414
3 changed files with 7 additions and 3 deletions

View File

@ -23,9 +23,7 @@ namespace Disk {
class Disk {
public:
virtual ~Disk() {
flush_tracks();
}
virtual ~Disk() {}
/*!
@returns the number of discrete positions that this disk uses to model its complete surface area.

View File

@ -21,7 +21,12 @@ Drive::Drive(unsigned int input_clock_rate, int revolutions_per_minute, int numb
available_heads_(number_of_heads) {
}
Drive::~Drive() {
if(disk_) disk_->flush_tracks();
}
void Drive::set_disk(const std::shared_ptr<Disk> &disk) {
if(disk_) disk_->flush_tracks();
disk_ = disk;
has_disk_ = !!disk_;

View File

@ -24,6 +24,7 @@ namespace Disk {
class Drive: public Sleeper, public TimedEventLoop {
public:
Drive(unsigned int input_clock_rate, int revolutions_per_minute, int number_of_heads);
~Drive();
/*!
Replaces whatever is in the drive with @c disk.