1
0
mirror of https://github.com/TomHarte/CLK.git synced 2025-01-13 07:30:21 +00:00

Cleans up all redundant lock/unique_guard declarations.

This commit is contained in:
Thomas Harte 2020-06-15 00:24:10 -04:00
parent 902b33d25d
commit 495024d6fe
18 changed files with 61 additions and 62 deletions

View File

@ -23,8 +23,8 @@ void MultiInterface<MachineType>::perform_parallel(const std::function<void(Mach
std::condition_variable condition; std::condition_variable condition;
std::mutex mutex; std::mutex mutex;
{ {
std::lock_guard<decltype(machines_mutex_)> machines_lock(machines_mutex_); std::lock_guard machines_lock(machines_mutex_);
std::lock_guard<std::mutex> lock(mutex); std::lock_guard lock(mutex);
outstanding_machines = machines_.size(); outstanding_machines = machines_.size();
for(std::size_t index = 0; index < machines_.size(); ++index) { for(std::size_t index = 0; index < machines_.size(); ++index) {
@ -32,20 +32,20 @@ void MultiInterface<MachineType>::perform_parallel(const std::function<void(Mach
queues_[index].enqueue([&mutex, &condition, machine, function, &outstanding_machines]() { queues_[index].enqueue([&mutex, &condition, machine, function, &outstanding_machines]() {
if(machine) function(machine); if(machine) function(machine);
std::lock_guard<std::mutex> lock(mutex); std::lock_guard lock(mutex);
outstanding_machines--; outstanding_machines--;
condition.notify_all(); condition.notify_all();
}); });
} }
} }
std::unique_lock<std::mutex> lock(mutex); std::unique_lock lock(mutex);
condition.wait(lock, [&outstanding_machines] { return !outstanding_machines; }); condition.wait(lock, [&outstanding_machines] { return !outstanding_machines; });
} }
template <typename MachineType> template <typename MachineType>
void MultiInterface<MachineType>::perform_serial(const std::function<void(MachineType *)> &function) { void MultiInterface<MachineType>::perform_serial(const std::function<void(MachineType *)> &function) {
std::lock_guard<decltype(machines_mutex_)> machines_lock(machines_mutex_); std::lock_guard machines_lock(machines_mutex_);
for(const auto &machine: machines_) { for(const auto &machine: machines_) {
const auto typed_machine = ::Machine::get<MachineType>(*machine.get()); const auto typed_machine = ::Machine::get<MachineType>(*machine.get());
if(typed_machine) function(typed_machine); if(typed_machine) function(typed_machine);
@ -56,13 +56,13 @@ void MultiInterface<MachineType>::perform_serial(const std::function<void(Machin
void MultiScanProducer::set_scan_target(Outputs::Display::ScanTarget *scan_target) { void MultiScanProducer::set_scan_target(Outputs::Display::ScanTarget *scan_target) {
scan_target_ = scan_target; scan_target_ = scan_target;
std::lock_guard<decltype(machines_mutex_)> machines_lock(machines_mutex_); std::lock_guard machines_lock(machines_mutex_);
const auto machine = machines_.front()->scan_producer(); const auto machine = machines_.front()->scan_producer();
if(machine) machine->set_scan_target(scan_target); if(machine) machine->set_scan_target(scan_target);
} }
Outputs::Display::ScanStatus MultiScanProducer::get_scan_status() const { Outputs::Display::ScanStatus MultiScanProducer::get_scan_status() const {
std::lock_guard<decltype(machines_mutex_)> machines_lock(machines_mutex_); std::lock_guard machines_lock(machines_mutex_);
const auto machine = machines_.front()->scan_producer(); const auto machine = machines_.front()->scan_producer();
if(machine) return machine->get_scan_status(); if(machine) return machine->get_scan_status();
return Outputs::Display::ScanStatus(); return Outputs::Display::ScanStatus();
@ -74,7 +74,7 @@ void MultiScanProducer::did_change_machine_order() {
perform_serial([](MachineTypes::ScanProducer *machine) { perform_serial([](MachineTypes::ScanProducer *machine) {
machine->set_scan_target(nullptr); machine->set_scan_target(nullptr);
}); });
std::lock_guard<decltype(machines_mutex_)> machines_lock(machines_mutex_); std::lock_guard machines_lock(machines_mutex_);
const auto machine = machines_.front()->scan_producer(); const auto machine = machines_.front()->scan_producer();
if(machine) machine->set_scan_target(scan_target_); if(machine) machine->set_scan_target(scan_target_);
} }

View File

@ -67,7 +67,7 @@ void MultiSpeaker::set_delegate(Outputs::Speaker::Speaker::Delegate *delegate) {
void MultiSpeaker::speaker_did_complete_samples(Speaker *speaker, const std::vector<int16_t> &buffer) { void MultiSpeaker::speaker_did_complete_samples(Speaker *speaker, const std::vector<int16_t> &buffer) {
if(!delegate_) return; if(!delegate_) return;
{ {
std::lock_guard<std::mutex> lock_guard(front_speaker_mutex_); std::lock_guard lock_guard(front_speaker_mutex_);
if(speaker != front_speaker_) return; if(speaker != front_speaker_) return;
} }
did_complete_samples(this, buffer, stereo_output_); did_complete_samples(this, buffer, stereo_output_);
@ -76,7 +76,7 @@ void MultiSpeaker::speaker_did_complete_samples(Speaker *speaker, const std::vec
void MultiSpeaker::speaker_did_change_input_clock(Speaker *speaker) { void MultiSpeaker::speaker_did_change_input_clock(Speaker *speaker) {
if(!delegate_) return; if(!delegate_) return;
{ {
std::lock_guard<std::mutex> lock_guard(front_speaker_mutex_); std::lock_guard lock_guard(front_speaker_mutex_);
if(speaker != front_speaker_) return; if(speaker != front_speaker_) return;
} }
delegate_->speaker_did_change_input_clock(this); delegate_->speaker_did_change_input_clock(this);
@ -84,7 +84,7 @@ void MultiSpeaker::speaker_did_change_input_clock(Speaker *speaker) {
void MultiSpeaker::set_new_front_machine(::Machine::DynamicMachine *machine) { void MultiSpeaker::set_new_front_machine(::Machine::DynamicMachine *machine) {
{ {
std::lock_guard<std::mutex> lock_guard(front_speaker_mutex_); std::lock_guard lock_guard(front_speaker_mutex_);
front_speaker_ = machine->audio_producer()->get_speaker(); front_speaker_ = machine->audio_producer()->get_speaker();
} }
if(delegate_) { if(delegate_) {

View File

@ -60,7 +60,7 @@ bool MultiMachine::would_collapse(const std::vector<std::unique_ptr<DynamicMachi
} }
void MultiMachine::did_run_machines(MultiTimedMachine *) { void MultiMachine::did_run_machines(MultiTimedMachine *) {
std::lock_guard<decltype(machines_mutex_)> machines_lock(machines_mutex_); std::lock_guard machines_lock(machines_mutex_);
#ifndef NDEBUG #ifndef NDEBUG
for(const auto &machine: machines_) { for(const auto &machine: machines_) {
auto timed_machine = machine->timed_machine(); auto timed_machine = machine->timed_machine();

View File

@ -23,7 +23,7 @@ AsyncTaskQueue::AsyncTaskQueue()
std::function<void(void)> next_function; std::function<void(void)> next_function;
// Take lock, check for a new task // Take lock, check for a new task
std::unique_lock<std::mutex> lock(queue_mutex_); std::unique_lock lock(queue_mutex_);
if(!pending_tasks_.empty()) { if(!pending_tasks_.empty()) {
next_function = pending_tasks_.front(); next_function = pending_tasks_.front();
pending_tasks_.pop_front(); pending_tasks_.pop_front();
@ -60,7 +60,7 @@ void AsyncTaskQueue::enqueue(std::function<void(void)> function) {
#ifdef __APPLE__ #ifdef __APPLE__
dispatch_async(serial_dispatch_queue_, ^{function();}); dispatch_async(serial_dispatch_queue_, ^{function();});
#else #else
std::lock_guard<std::mutex> lock(queue_mutex_); std::lock_guard lock(queue_mutex_);
pending_tasks_.push_back(function); pending_tasks_.push_back(function);
processing_condition_.notify_all(); processing_condition_.notify_all();
#endif #endif
@ -72,9 +72,9 @@ void AsyncTaskQueue::flush() {
#else #else
auto flush_mutex = std::make_shared<std::mutex>(); auto flush_mutex = std::make_shared<std::mutex>();
auto flush_condition = std::make_shared<std::condition_variable>(); auto flush_condition = std::make_shared<std::condition_variable>();
std::unique_lock<std::mutex> lock(*flush_mutex); std::unique_lock lock(*flush_mutex);
enqueue([=] () { enqueue([=] () {
std::unique_lock<std::mutex> inner_lock(*flush_mutex); std::unique_lock inner_lock(*flush_mutex);
flush_condition->notify_all(); flush_condition->notify_all();
}); });
flush_condition->wait(lock); flush_condition->wait(lock);

View File

@ -210,7 +210,7 @@ class Keyboard {
void enqueue_key_state(uint16_t key, bool is_pressed) { void enqueue_key_state(uint16_t key, bool is_pressed) {
// Front insert; messages will be pop_back'd. // Front insert; messages will be pop_back'd.
std::lock_guard<decltype(key_queue_mutex_)> lock(key_queue_mutex_); std::lock_guard lock(key_queue_mutex_);
// Keys on the keypad are preceded by a $79 keycode; in the internal naming scheme // Keys on the keypad are preceded by a $79 keycode; in the internal naming scheme
// they are indicated by having bit 8 set. So add the $79 prefix if required. // they are indicated by having bit 8 set. So add the $79 prefix if required.
@ -228,7 +228,7 @@ class Keyboard {
switch(command) { switch(command) {
case 0x10: // Inquiry. case 0x10: // Inquiry.
case 0x14: { // Instant. case 0x14: { // Instant.
std::lock_guard<decltype(key_queue_mutex_)> lock(key_queue_mutex_); std::lock_guard lock(key_queue_mutex_);
if(!key_queue_.empty()) { if(!key_queue_.empty()) {
const auto new_message = key_queue_.back(); const auto new_message = key_queue_.back();
key_queue_.pop_back(); key_queue_.pop_back();

View File

@ -84,7 +84,7 @@ void IntelligentKeyboard::run_for(HalfCycles duration) {
// Forward key changes; implicit assumption here: mutexs are cheap while there's // Forward key changes; implicit assumption here: mutexs are cheap while there's
// negligible contention. // negligible contention.
{ {
std::lock_guard<decltype(key_queue_mutex_)> guard(key_queue_mutex_); std::lock_guard guard(key_queue_mutex_);
for(uint8_t key: key_queue_) { for(uint8_t key: key_queue_) {
output_bytes({key}); output_bytes({key});
} }
@ -348,7 +348,7 @@ void IntelligentKeyboard::post_relative_mouse_event(int x, int y) {
// MARK: - Keyboard Input // MARK: - Keyboard Input
void IntelligentKeyboard::set_key_state(Key key, bool is_pressed) { void IntelligentKeyboard::set_key_state(Key key, bool is_pressed) {
std::lock_guard<decltype(key_queue_mutex_)> guard(key_queue_mutex_); std::lock_guard guard(key_queue_mutex_);
if(is_pressed) { if(is_pressed) {
key_queue_.push_back(uint8_t(key)); key_queue_.push_back(uint8_t(key));
} else { } else {

View File

@ -25,7 +25,6 @@ class FunctionThread: public QThread {
} }
void stop() { void stop() {
// QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection);
quit(); quit();
wait(); wait();
} }

View File

@ -118,7 +118,7 @@ struct MachineRunner {
std::atomic<double> _frame_period; std::atomic<double> _frame_period;
static constexpr Uint32 timer_period = 4; static constexpr Uint32 timer_period = 4;
static Uint32 sdl_callback(Uint32 interval, void *param) { static Uint32 sdl_callback(Uint32, void *param) {
reinterpret_cast<MachineRunner *>(param)->update(); reinterpret_cast<MachineRunner *>(param)->update();
return timer_period; return timer_period;
} }
@ -140,7 +140,7 @@ struct MachineRunner {
const auto vsync_time = vsync_time_.load(); const auto vsync_time = vsync_time_.load();
std::unique_lock<std::mutex> lock_guard(*machine_mutex); std::unique_lock lock_guard(*machine_mutex);
const auto scan_producer = machine->scan_producer(); const auto scan_producer = machine->scan_producer();
const auto timed_machine = machine->timed_machine(); const auto timed_machine = machine->timed_machine();
@ -176,8 +176,8 @@ struct SpeakerDelegate: public Outputs::Speaker::Speaker::Delegate {
static constexpr size_t buffered_samples = 1024; static constexpr size_t buffered_samples = 1024;
bool is_stereo = false; bool is_stereo = false;
void speaker_did_complete_samples(Outputs::Speaker::Speaker *speaker, const std::vector<int16_t> &buffer) final { void speaker_did_complete_samples(Outputs::Speaker::Speaker *, const std::vector<int16_t> &buffer) final {
std::lock_guard<std::mutex> lock_guard(audio_buffer_mutex_); std::lock_guard lock_guard(audio_buffer_mutex_);
const size_t buffer_size = buffered_samples * (is_stereo ? 2 : 1); const size_t buffer_size = buffered_samples * (is_stereo ? 2 : 1);
if(audio_buffer_.size() > buffer_size) { if(audio_buffer_.size() > buffer_size) {
audio_buffer_.erase(audio_buffer_.begin(), audio_buffer_.end() - buffer_size); audio_buffer_.erase(audio_buffer_.begin(), audio_buffer_.end() - buffer_size);
@ -186,7 +186,7 @@ struct SpeakerDelegate: public Outputs::Speaker::Speaker::Delegate {
} }
void audio_callback(Uint8 *stream, int len) { void audio_callback(Uint8 *stream, int len) {
std::lock_guard<std::mutex> lock_guard(audio_buffer_mutex_); std::lock_guard lock_guard(audio_buffer_mutex_);
// SDL buffer length is in bytes, so there's no need to adjust for stereo/mono in here. // SDL buffer length is in bytes, so there's no need to adjust for stereo/mono in here.
const std::size_t sample_length = size_t(len) / sizeof(int16_t); const std::size_t sample_length = size_t(len) / sizeof(int16_t);
@ -234,7 +234,7 @@ class ActivityObserver: public Activity::Observer {
} }
void set_aspect_ratio(float aspect_ratio) { void set_aspect_ratio(float aspect_ratio) {
std::lock_guard<std::mutex> lock_guard(mutex); std::lock_guard lock_guard(mutex);
lights_.clear(); lights_.clear();
// Generate a bunch of LEDs for connected drives. // Generate a bunch of LEDs for connected drives.
@ -261,7 +261,7 @@ class ActivityObserver: public Activity::Observer {
} }
void draw() { void draw() {
std::lock_guard<std::mutex> lock_guard(mutex); std::lock_guard lock_guard(mutex);
for(const auto &lit_led: lit_leds_) { for(const auto &lit_led: lit_leds_) {
if(blinking_leds_.find(lit_led) == blinking_leds_.end() && lights_.find(lit_led) != lights_.end()) if(blinking_leds_.find(lit_led) == blinking_leds_.end() && lights_.find(lit_led) != lights_.end())
lights_[lit_led]->draw(0.0, 0.8, 0.0); lights_[lit_led]->draw(0.0, 0.8, 0.0);
@ -272,24 +272,24 @@ class ActivityObserver: public Activity::Observer {
private: private:
std::vector<std::string> leds_; std::vector<std::string> leds_;
void register_led(const std::string &name) final { void register_led(const std::string &name) final {
std::lock_guard<std::mutex> lock_guard(mutex); std::lock_guard lock_guard(mutex);
leds_.push_back(name); leds_.push_back(name);
} }
std::vector<std::string> drives_; std::vector<std::string> drives_;
void register_drive(const std::string &name) final { void register_drive(const std::string &name) final {
std::lock_guard<std::mutex> lock_guard(mutex); std::lock_guard lock_guard(mutex);
drives_.push_back(name); drives_.push_back(name);
} }
void set_led_status(const std::string &name, bool lit) final { void set_led_status(const std::string &name, bool lit) final {
std::lock_guard<std::mutex> lock_guard(mutex); std::lock_guard lock_guard(mutex);
if(lit) lit_leds_.insert(name); if(lit) lit_leds_.insert(name);
else lit_leds_.erase(name); else lit_leds_.erase(name);
} }
void announce_drive_event(const std::string &name, DriveEvent event) final { void announce_drive_event(const std::string &name, DriveEvent) final {
std::lock_guard<std::mutex> lock_guard(mutex); std::lock_guard lock_guard(mutex);
blinking_leds_.insert(name); blinking_leds_.insert(name);
} }
@ -963,7 +963,7 @@ int main(int argc, char *argv[]) {
// on vsync, anyway. // on vsync, anyway.
// Grab the machine lock and process all pending events. // Grab the machine lock and process all pending events.
std::lock_guard<std::mutex> lock_guard(machine_mutex); std::lock_guard lock_guard(machine_mutex);
const auto keyboard_machine = machine->keyboard_machine(); const auto keyboard_machine = machine->keyboard_machine();
SDL_Event event; SDL_Event event;
while(SDL_PollEvent(&event)) { while(SDL_PollEvent(&event)) {

View File

@ -288,12 +288,12 @@ void Shader::set_uniform_matrix(const std::string &name, GLint size, GLsizei cou
} }
void Shader::enqueue_function(std::function<void(void)> function) { void Shader::enqueue_function(std::function<void(void)> function) {
std::lock_guard<std::mutex> function_guard(function_mutex_); std::lock_guard function_guard(function_mutex_);
enqueued_functions_.push_back(function); enqueued_functions_.push_back(function);
} }
void Shader::flush_functions() const { void Shader::flush_functions() const {
std::lock_guard<std::mutex> function_guard(function_mutex_); std::lock_guard function_guard(function_mutex_);
for(std::function<void(void)> function : enqueued_functions_) { for(std::function<void(void)> function : enqueued_functions_) {
function(); function();
} }

View File

@ -131,7 +131,7 @@ void ScanTarget::set_modals(Modals modals) {
Outputs::Display::ScanTarget::Scan *ScanTarget::begin_scan() { Outputs::Display::ScanTarget::Scan *ScanTarget::begin_scan() {
if(allocation_has_failed_) return nullptr; if(allocation_has_failed_) return nullptr;
std::lock_guard<std::mutex> lock_guard(write_pointers_mutex_); std::lock_guard lock_guard(write_pointers_mutex_);
const auto result = &scan_buffer_[write_pointers_.scan_buffer]; const auto result = &scan_buffer_[write_pointers_.scan_buffer];
const auto read_pointers = read_pointers_.load(); const auto read_pointers = read_pointers_.load();
@ -156,7 +156,7 @@ Outputs::Display::ScanTarget::Scan *ScanTarget::begin_scan() {
void ScanTarget::end_scan() { void ScanTarget::end_scan() {
if(vended_scan_) { if(vended_scan_) {
std::lock_guard<std::mutex> lock_guard(write_pointers_mutex_); std::lock_guard lock_guard(write_pointers_mutex_);
vended_scan_->data_y = TextureAddressGetY(vended_write_area_pointer_); vended_scan_->data_y = TextureAddressGetY(vended_write_area_pointer_);
vended_scan_->line = write_pointers_.line; vended_scan_->line = write_pointers_.line;
vended_scan_->scan.end_points[0].data_offset += TextureAddressGetX(vended_write_area_pointer_); vended_scan_->scan.end_points[0].data_offset += TextureAddressGetX(vended_write_area_pointer_);
@ -181,7 +181,7 @@ uint8_t *ScanTarget::begin_data(size_t required_length, size_t required_alignmen
if(allocation_has_failed_) return nullptr; if(allocation_has_failed_) return nullptr;
std::lock_guard<std::mutex> lock_guard(write_pointers_mutex_); std::lock_guard lock_guard(write_pointers_mutex_);
if(write_area_texture_.empty()) { if(write_area_texture_.empty()) {
allocation_has_failed_ = true; allocation_has_failed_ = true;
return nullptr; return nullptr;
@ -229,7 +229,7 @@ uint8_t *ScanTarget::begin_data(size_t required_length, size_t required_alignmen
void ScanTarget::end_data(size_t actual_length) { void ScanTarget::end_data(size_t actual_length) {
if(allocation_has_failed_ || !data_is_allocated_) return; if(allocation_has_failed_ || !data_is_allocated_) return;
std::lock_guard<std::mutex> lock_guard(write_pointers_mutex_); std::lock_guard lock_guard(write_pointers_mutex_);
// Bookend the start of the new data, to safeguard for precision errors in sampling. // Bookend the start of the new data, to safeguard for precision errors in sampling.
memcpy( memcpy(
@ -277,7 +277,7 @@ void ScanTarget::announce(Event event, bool is_visible, const Outputs::Display::
if(output_is_visible_ == is_visible) return; if(output_is_visible_ == is_visible) return;
if(is_visible) { if(is_visible) {
const auto read_pointers = read_pointers_.load(); const auto read_pointers = read_pointers_.load();
std::lock_guard<std::mutex> lock_guard(write_pointers_mutex_); std::lock_guard lock_guard(write_pointers_mutex_);
// Commit the most recent line only if any scans fell on it. // Commit the most recent line only if any scans fell on it.
// Otherwise there's no point outputting it, it'll contribute nothing. // Otherwise there's no point outputting it, it'll contribute nothing.
@ -350,7 +350,7 @@ void ScanTarget::setup_pipeline() {
// Ensure the lock guard here has a restricted scope; this is the only time that a thread // Ensure the lock guard here has a restricted scope; this is the only time that a thread
// other than the main owner of write_pointers_ may adjust it. // other than the main owner of write_pointers_ may adjust it.
{ {
std::lock_guard<std::mutex> lock_guard(write_pointers_mutex_); std::lock_guard lock_guard(write_pointers_mutex_);
if(data_type_size != data_type_size_) { if(data_type_size != data_type_size_) {
// TODO: flush output. // TODO: flush output.

View File

@ -43,7 +43,7 @@ template <typename SampleSource> class LowpassSpeaker: public Speaker {
// Implemented as per Speaker. // Implemented as per Speaker.
float get_ideal_clock_rate_in_range(float minimum, float maximum) final { float get_ideal_clock_rate_in_range(float minimum, float maximum) final {
std::lock_guard<std::mutex> lock_guard(filter_parameters_mutex_); std::lock_guard lock_guard(filter_parameters_mutex_);
// return twice the cut off, if applicable // return twice the cut off, if applicable
if( filter_parameters_.high_frequency_cutoff > 0.0f && if( filter_parameters_.high_frequency_cutoff > 0.0f &&
@ -66,7 +66,7 @@ template <typename SampleSource> class LowpassSpeaker: public Speaker {
// Implemented as per Speaker. // Implemented as per Speaker.
void set_computed_output_rate(float cycles_per_second, int buffer_size, bool) final { void set_computed_output_rate(float cycles_per_second, int buffer_size, bool) final {
std::lock_guard<std::mutex> lock_guard(filter_parameters_mutex_); std::lock_guard lock_guard(filter_parameters_mutex_);
if(filter_parameters_.output_cycles_per_second == cycles_per_second && size_t(buffer_size) == output_buffer_.size()) { if(filter_parameters_.output_cycles_per_second == cycles_per_second && size_t(buffer_size) == output_buffer_.size()) {
return; return;
} }
@ -84,7 +84,7 @@ template <typename SampleSource> class LowpassSpeaker: public Speaker {
Sets the clock rate of the input audio. Sets the clock rate of the input audio.
*/ */
void set_input_rate(float cycles_per_second) { void set_input_rate(float cycles_per_second) {
std::lock_guard<std::mutex> lock_guard(filter_parameters_mutex_); std::lock_guard lock_guard(filter_parameters_mutex_);
if(filter_parameters_.input_cycles_per_second == cycles_per_second) { if(filter_parameters_.input_cycles_per_second == cycles_per_second) {
return; return;
} }
@ -100,7 +100,7 @@ template <typename SampleSource> class LowpassSpeaker: public Speaker {
path to be explicit about its effect, and get that simulation for free. path to be explicit about its effect, and get that simulation for free.
*/ */
void set_high_frequency_cutoff(float high_frequency) { void set_high_frequency_cutoff(float high_frequency) {
std::lock_guard<std::mutex> lock_guard(filter_parameters_mutex_); std::lock_guard lock_guard(filter_parameters_mutex_);
if(filter_parameters_.high_frequency_cutoff == high_frequency) { if(filter_parameters_.high_frequency_cutoff == high_frequency) {
return; return;
} }
@ -141,7 +141,7 @@ template <typename SampleSource> class LowpassSpeaker: public Speaker {
FilterParameters filter_parameters; FilterParameters filter_parameters;
{ {
std::lock_guard<std::mutex> lock_guard(filter_parameters_mutex_); std::lock_guard lock_guard(filter_parameters_mutex_);
filter_parameters = filter_parameters_; filter_parameters = filter_parameters_;
filter_parameters_.parameters_are_dirty = false; filter_parameters_.parameters_are_dirty = false;
filter_parameters_.input_rate_changed = false; filter_parameters_.input_rate_changed = false;

View File

@ -64,7 +64,7 @@ size_t AppleDSK::logical_sector_for_physical_sector(size_t physical) {
std::shared_ptr<Track> AppleDSK::get_track_at_position(Track::Address address) { std::shared_ptr<Track> AppleDSK::get_track_at_position(Track::Address address) {
std::vector<uint8_t> track_data; std::vector<uint8_t> track_data;
{ {
std::lock_guard<std::mutex> lock_guard(file_.get_file_access_mutex()); std::lock_guard lock_guard(file_.get_file_access_mutex());
file_.seek(file_offset(address), SEEK_SET); file_.seek(file_offset(address), SEEK_SET);
track_data = file_.read(size_t(bytes_per_sector * sectors_per_track_)); track_data = file_.read(size_t(bytes_per_sector * sectors_per_track_));
} }
@ -115,7 +115,7 @@ void AppleDSK::set_tracks(const std::map<Track::Address, std::shared_ptr<Track>>
} }
// Grab the file lock and write out the new tracks. // Grab the file lock and write out the new tracks.
std::lock_guard<std::mutex> lock_guard(file_.get_file_access_mutex()); std::lock_guard lock_guard(file_.get_file_access_mutex());
for(const auto &pair: tracks_by_address) { for(const auto &pair: tracks_by_address) {
file_.seek(file_offset(pair.first), SEEK_SET); file_.seek(file_offset(pair.first), SEEK_SET);
file_.write(pair.second); file_.write(pair.second);

View File

@ -58,7 +58,7 @@ uint16_t HFE::seek_track(Track::Address address) {
std::shared_ptr<Track> HFE::get_track_at_position(Track::Address address) { std::shared_ptr<Track> HFE::get_track_at_position(Track::Address address) {
PCMSegment segment; PCMSegment segment;
{ {
std::lock_guard<std::mutex> lock_guard(file_.get_file_access_mutex()); std::lock_guard lock_guard(file_.get_file_access_mutex());
uint16_t track_length = seek_track(address); uint16_t track_length = seek_track(address);
segment.data.resize(track_length * 8); segment.data.resize(track_length * 8);
@ -102,7 +102,7 @@ std::shared_ptr<Track> HFE::get_track_at_position(Track::Address address) {
void HFE::set_tracks(const std::map<Track::Address, std::shared_ptr<Track>> &tracks) { void HFE::set_tracks(const std::map<Track::Address, std::shared_ptr<Track>> &tracks) {
for(auto &track : tracks) { for(auto &track : tracks) {
std::unique_lock<std::mutex> lock_guard(file_.get_file_access_mutex()); std::unique_lock lock_guard(file_.get_file_access_mutex());
uint16_t track_length = seek_track(track.first); uint16_t track_length = seek_track(track.first);
lock_guard.unlock(); lock_guard.unlock();

View File

@ -29,7 +29,7 @@ std::shared_ptr<Track> MFMSectorDump::get_track_at_position(Track::Address addre
const long file_offset = get_file_offset_for_position(address); const long file_offset = get_file_offset_for_position(address);
{ {
std::lock_guard<std::mutex> lock_guard(file_.get_file_access_mutex()); std::lock_guard lock_guard(file_.get_file_access_mutex());
file_.seek(file_offset, SEEK_SET); file_.seek(file_offset, SEEK_SET);
file_.read(sectors, sizeof(sectors)); file_.read(sectors, sizeof(sectors));
} }
@ -48,7 +48,7 @@ void MFMSectorDump::set_tracks(const std::map<Track::Address, std::shared_ptr<Tr
decode_sectors(*track.second, parsed_track, first_sector_, first_sector_ + uint8_t(sectors_per_track_-1), sector_size_, is_double_density_); decode_sectors(*track.second, parsed_track, first_sector_, first_sector_ + uint8_t(sectors_per_track_-1), sector_size_, is_double_density_);
const long file_offset = get_file_offset_for_position(track.first); const long file_offset = get_file_offset_for_position(track.first);
std::lock_guard<std::mutex> lock_guard(file_.get_file_access_mutex()); std::lock_guard lock_guard(file_.get_file_access_mutex());
file_.ensure_is_at_least_length(file_offset); file_.ensure_is_at_least_length(file_offset);
file_.seek(file_offset, SEEK_SET); file_.seek(file_offset, SEEK_SET);
file_.write(parsed_track, sizeof(parsed_track)); file_.write(parsed_track, sizeof(parsed_track));

View File

@ -169,7 +169,7 @@ std::shared_ptr<::Storage::Disk::Track> MacintoshIMG::get_track_at_position(::St
Bit 5 indicates double sided or not. Bit 5 indicates double sided or not.
*/ */
std::lock_guard<decltype(buffer_mutex_)> buffer_lock(buffer_mutex_); std::lock_guard buffer_lock(buffer_mutex_);
if(encoding_ == Encoding::GCR400 || encoding_ == Encoding::GCR800) { if(encoding_ == Encoding::GCR400 || encoding_ == Encoding::GCR800) {
// Perform a GCR encoding. // Perform a GCR encoding.
const auto included_sectors = Storage::Encodings::AppleGCR::Macintosh::sectors_in_track(address.position.as_int()); const auto included_sectors = Storage::Encodings::AppleGCR::Macintosh::sectors_in_track(address.position.as_int());
@ -259,7 +259,7 @@ void MacintoshIMG::set_tracks(const std::map<Track::Address, std::shared_ptr<Tra
// Grab the buffer mutex and update the in-memory buffer. // Grab the buffer mutex and update the in-memory buffer.
{ {
std::lock_guard<decltype(buffer_mutex_)> buffer_lock(buffer_mutex_); std::lock_guard buffer_lock(buffer_mutex_);
for(const auto &pair: tracks_by_address) { for(const auto &pair: tracks_by_address) {
const auto included_sectors = Storage::Encodings::AppleGCR::Macintosh::sectors_in_track(pair.first.position.as_int()); const auto included_sectors = Storage::Encodings::AppleGCR::Macintosh::sectors_in_track(pair.first.position.as_int());
size_t start_sector = size_t(included_sectors.start * get_head_count() + included_sectors.length * pair.first.head); size_t start_sector = size_t(included_sectors.start * get_head_count() + included_sectors.length * pair.first.head);
@ -283,7 +283,7 @@ void MacintoshIMG::set_tracks(const std::map<Track::Address, std::shared_ptr<Tra
// Grab the file lock and write out the new tracks. // Grab the file lock and write out the new tracks.
{ {
std::lock_guard<std::mutex> lock_guard(file_.get_file_access_mutex()); std::lock_guard lock_guard(file_.get_file_access_mutex());
if(!is_diskCopy_file_) { if(!is_diskCopy_file_) {
// Just dump out the new sectors. Grossly lazy, possibly worth improving. // Just dump out the new sectors. Grossly lazy, possibly worth improving.

View File

@ -61,7 +61,7 @@ std::shared_ptr<::Storage::Disk::Track> NIB::get_track_at_position(::Storage::Di
long offset = file_offset(address); long offset = file_offset(address);
std::vector<uint8_t> track_data; std::vector<uint8_t> track_data;
{ {
std::lock_guard<std::mutex> lock_guard(file_.get_file_access_mutex()); std::lock_guard lock_guard(file_.get_file_access_mutex());
file_.seek(offset, SEEK_SET); file_.seek(offset, SEEK_SET);
track_data = file_.read(track_length); track_data = file_.read(track_length);
} }
@ -189,7 +189,7 @@ void NIB::set_tracks(const std::map<Track::Address, std::shared_ptr<Track>> &tra
} }
// Lock the file and spool out. // Lock the file and spool out.
std::lock_guard<std::mutex> lock_guard(file_.get_file_access_mutex()); std::lock_guard lock_guard(file_.get_file_access_mutex());
for(const auto &track: tracks_by_address) { for(const auto &track: tracks_by_address) {
file_.seek(file_offset(track.first), SEEK_SET); file_.seek(file_offset(track.first), SEEK_SET);
file_.write(track.second); file_.write(track.second);

View File

@ -53,7 +53,7 @@ long OricMFMDSK::get_file_offset_for_position(Track::Address address) {
std::shared_ptr<Track> OricMFMDSK::get_track_at_position(Track::Address address) { std::shared_ptr<Track> OricMFMDSK::get_track_at_position(Track::Address address) {
PCMSegment segment; PCMSegment segment;
{ {
std::lock_guard<std::mutex> lock_guard(file_.get_file_access_mutex()); std::lock_guard lock_guard(file_.get_file_access_mutex());
file_.seek(get_file_offset_for_position(address), SEEK_SET); file_.seek(get_file_offset_for_position(address), SEEK_SET);
// The file format omits clock bits. So it's not a genuine MFM capture. // The file format omits clock bits. So it's not a genuine MFM capture.
@ -157,7 +157,7 @@ void OricMFMDSK::set_tracks(const std::map<Track::Address, std::shared_ptr<Track
long file_offset = get_file_offset_for_position(track.first); long file_offset = get_file_offset_for_position(track.first);
std::lock_guard<std::mutex> lock_guard(file_.get_file_access_mutex()); std::lock_guard lock_guard(file_.get_file_access_mutex());
file_.seek(file_offset, SEEK_SET); file_.seek(file_offset, SEEK_SET);
std::size_t track_size = std::min(size_t(6400), parsed_track.size()); std::size_t track_size = std::min(size_t(6400), parsed_track.size());
file_.write(parsed_track.data(), track_size); file_.write(parsed_track.data(), track_size);

View File

@ -110,7 +110,7 @@ std::shared_ptr<Track> WOZ::get_track_at_position(Track::Address address) {
std::vector<uint8_t> track_contents; std::vector<uint8_t> track_contents;
size_t number_of_bits; size_t number_of_bits;
{ {
std::lock_guard<std::mutex> lock_guard(file_.get_file_access_mutex()); std::lock_guard lock_guard(file_.get_file_access_mutex());
file_.seek(offset, SEEK_SET); file_.seek(offset, SEEK_SET);
// In WOZ a track is up to 6646 bytes of data, followed by a two-byte record of the // In WOZ a track is up to 6646 bytes of data, followed by a two-byte record of the
@ -148,7 +148,7 @@ void WOZ::set_tracks(const std::map<Track::Address, std::shared_ptr<Track>> &tra
const uint32_t crc = crc_generator.compute_crc(post_crc_contents_); const uint32_t crc = crc_generator.compute_crc(post_crc_contents_);
// Grab the file lock, then write the CRC, then just dump the entire file buffer. // Grab the file lock, then write the CRC, then just dump the entire file buffer.
std::lock_guard<std::mutex> lock_guard(file_.get_file_access_mutex()); std::lock_guard lock_guard(file_.get_file_access_mutex());
file_.seek(8, SEEK_SET); file_.seek(8, SEEK_SET);
file_.put_le(crc); file_.put_le(crc);
file_.write(post_crc_contents_); file_.write(post_crc_contents_);