mirror of
https://github.com/TomHarte/CLK.git
synced 2024-12-25 18:30:21 +00:00
Cleans up all redundant lock/unique_guard declarations.
This commit is contained in:
parent
902b33d25d
commit
495024d6fe
@ -23,8 +23,8 @@ void MultiInterface<MachineType>::perform_parallel(const std::function<void(Mach
|
||||
std::condition_variable condition;
|
||||
std::mutex mutex;
|
||||
{
|
||||
std::lock_guard<decltype(machines_mutex_)> machines_lock(machines_mutex_);
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
std::lock_guard machines_lock(machines_mutex_);
|
||||
std::lock_guard lock(mutex);
|
||||
outstanding_machines = machines_.size();
|
||||
|
||||
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]() {
|
||||
if(machine) function(machine);
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
std::lock_guard lock(mutex);
|
||||
outstanding_machines--;
|
||||
condition.notify_all();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
std::unique_lock lock(mutex);
|
||||
condition.wait(lock, [&outstanding_machines] { return !outstanding_machines; });
|
||||
}
|
||||
|
||||
template <typename MachineType>
|
||||
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_) {
|
||||
const auto typed_machine = ::Machine::get<MachineType>(*machine.get());
|
||||
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) {
|
||||
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();
|
||||
if(machine) machine->set_scan_target(scan_target);
|
||||
}
|
||||
|
||||
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();
|
||||
if(machine) return machine->get_scan_status();
|
||||
return Outputs::Display::ScanStatus();
|
||||
@ -74,7 +74,7 @@ void MultiScanProducer::did_change_machine_order() {
|
||||
perform_serial([](MachineTypes::ScanProducer *machine) {
|
||||
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();
|
||||
if(machine) machine->set_scan_target(scan_target_);
|
||||
}
|
||||
|
@ -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) {
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
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;
|
||||
}
|
||||
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) {
|
||||
{
|
||||
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();
|
||||
}
|
||||
if(delegate_) {
|
||||
|
@ -60,7 +60,7 @@ bool MultiMachine::would_collapse(const std::vector<std::unique_ptr<DynamicMachi
|
||||
}
|
||||
|
||||
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
|
||||
for(const auto &machine: machines_) {
|
||||
auto timed_machine = machine->timed_machine();
|
||||
|
@ -23,7 +23,7 @@ AsyncTaskQueue::AsyncTaskQueue()
|
||||
std::function<void(void)> next_function;
|
||||
|
||||
// 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()) {
|
||||
next_function = pending_tasks_.front();
|
||||
pending_tasks_.pop_front();
|
||||
@ -60,7 +60,7 @@ void AsyncTaskQueue::enqueue(std::function<void(void)> function) {
|
||||
#ifdef __APPLE__
|
||||
dispatch_async(serial_dispatch_queue_, ^{function();});
|
||||
#else
|
||||
std::lock_guard<std::mutex> lock(queue_mutex_);
|
||||
std::lock_guard lock(queue_mutex_);
|
||||
pending_tasks_.push_back(function);
|
||||
processing_condition_.notify_all();
|
||||
#endif
|
||||
@ -72,9 +72,9 @@ void AsyncTaskQueue::flush() {
|
||||
#else
|
||||
auto flush_mutex = std::make_shared<std::mutex>();
|
||||
auto flush_condition = std::make_shared<std::condition_variable>();
|
||||
std::unique_lock<std::mutex> lock(*flush_mutex);
|
||||
std::unique_lock lock(*flush_mutex);
|
||||
enqueue([=] () {
|
||||
std::unique_lock<std::mutex> inner_lock(*flush_mutex);
|
||||
std::unique_lock inner_lock(*flush_mutex);
|
||||
flush_condition->notify_all();
|
||||
});
|
||||
flush_condition->wait(lock);
|
||||
|
@ -210,7 +210,7 @@ class Keyboard {
|
||||
|
||||
void enqueue_key_state(uint16_t key, bool is_pressed) {
|
||||
// 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
|
||||
// they are indicated by having bit 8 set. So add the $79 prefix if required.
|
||||
@ -228,7 +228,7 @@ class Keyboard {
|
||||
switch(command) {
|
||||
case 0x10: // Inquiry.
|
||||
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()) {
|
||||
const auto new_message = key_queue_.back();
|
||||
key_queue_.pop_back();
|
||||
|
@ -84,7 +84,7 @@ void IntelligentKeyboard::run_for(HalfCycles duration) {
|
||||
// Forward key changes; implicit assumption here: mutexs are cheap while there's
|
||||
// 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_) {
|
||||
output_bytes({key});
|
||||
}
|
||||
@ -348,7 +348,7 @@ void IntelligentKeyboard::post_relative_mouse_event(int x, int y) {
|
||||
|
||||
// MARK: - Keyboard Input
|
||||
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) {
|
||||
key_queue_.push_back(uint8_t(key));
|
||||
} else {
|
||||
|
@ -25,7 +25,6 @@ class FunctionThread: public QThread {
|
||||
}
|
||||
|
||||
void stop() {
|
||||
// QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection);
|
||||
quit();
|
||||
wait();
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ struct MachineRunner {
|
||||
std::atomic<double> _frame_period;
|
||||
|
||||
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();
|
||||
return timer_period;
|
||||
}
|
||||
@ -140,7 +140,7 @@ struct MachineRunner {
|
||||
|
||||
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 timed_machine = machine->timed_machine();
|
||||
|
||||
@ -176,8 +176,8 @@ struct SpeakerDelegate: public Outputs::Speaker::Speaker::Delegate {
|
||||
static constexpr size_t buffered_samples = 1024;
|
||||
bool is_stereo = false;
|
||||
|
||||
void speaker_did_complete_samples(Outputs::Speaker::Speaker *speaker, const std::vector<int16_t> &buffer) final {
|
||||
std::lock_guard<std::mutex> lock_guard(audio_buffer_mutex_);
|
||||
void speaker_did_complete_samples(Outputs::Speaker::Speaker *, const std::vector<int16_t> &buffer) final {
|
||||
std::lock_guard lock_guard(audio_buffer_mutex_);
|
||||
const size_t buffer_size = buffered_samples * (is_stereo ? 2 : 1);
|
||||
if(audio_buffer_.size() > 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) {
|
||||
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.
|
||||
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) {
|
||||
std::lock_guard<std::mutex> lock_guard(mutex);
|
||||
std::lock_guard lock_guard(mutex);
|
||||
lights_.clear();
|
||||
|
||||
// Generate a bunch of LEDs for connected drives.
|
||||
@ -261,7 +261,7 @@ class ActivityObserver: public Activity::Observer {
|
||||
}
|
||||
|
||||
void draw() {
|
||||
std::lock_guard<std::mutex> lock_guard(mutex);
|
||||
std::lock_guard lock_guard(mutex);
|
||||
for(const auto &lit_led: lit_leds_) {
|
||||
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);
|
||||
@ -272,24 +272,24 @@ class ActivityObserver: public Activity::Observer {
|
||||
private:
|
||||
std::vector<std::string> leds_;
|
||||
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);
|
||||
}
|
||||
|
||||
std::vector<std::string> drives_;
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
else lit_leds_.erase(name);
|
||||
}
|
||||
|
||||
void announce_drive_event(const std::string &name, DriveEvent event) final {
|
||||
std::lock_guard<std::mutex> lock_guard(mutex);
|
||||
void announce_drive_event(const std::string &name, DriveEvent) final {
|
||||
std::lock_guard lock_guard(mutex);
|
||||
blinking_leds_.insert(name);
|
||||
}
|
||||
|
||||
@ -963,7 +963,7 @@ int main(int argc, char *argv[]) {
|
||||
// on vsync, anyway.
|
||||
|
||||
// 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();
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event)) {
|
||||
|
@ -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) {
|
||||
std::lock_guard<std::mutex> function_guard(function_mutex_);
|
||||
std::lock_guard function_guard(function_mutex_);
|
||||
enqueued_functions_.push_back(function);
|
||||
}
|
||||
|
||||
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_) {
|
||||
function();
|
||||
}
|
||||
|
@ -131,7 +131,7 @@ void ScanTarget::set_modals(Modals modals) {
|
||||
Outputs::Display::ScanTarget::Scan *ScanTarget::begin_scan() {
|
||||
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 read_pointers = read_pointers_.load();
|
||||
@ -156,7 +156,7 @@ Outputs::Display::ScanTarget::Scan *ScanTarget::begin_scan() {
|
||||
|
||||
void ScanTarget::end_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_->line = write_pointers_.line;
|
||||
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;
|
||||
|
||||
std::lock_guard<std::mutex> lock_guard(write_pointers_mutex_);
|
||||
std::lock_guard lock_guard(write_pointers_mutex_);
|
||||
if(write_area_texture_.empty()) {
|
||||
allocation_has_failed_ = true;
|
||||
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) {
|
||||
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.
|
||||
memcpy(
|
||||
@ -277,7 +277,7 @@ void ScanTarget::announce(Event event, bool is_visible, const Outputs::Display::
|
||||
if(output_is_visible_ == is_visible) return;
|
||||
if(is_visible) {
|
||||
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.
|
||||
// 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
|
||||
// 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_) {
|
||||
// TODO: flush output.
|
||||
|
||||
|
@ -43,7 +43,7 @@ template <typename SampleSource> class LowpassSpeaker: public Speaker {
|
||||
|
||||
// Implemented as per Speaker.
|
||||
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
|
||||
if( filter_parameters_.high_frequency_cutoff > 0.0f &&
|
||||
@ -66,7 +66,7 @@ template <typename SampleSource> class LowpassSpeaker: public Speaker {
|
||||
|
||||
// Implemented as per Speaker.
|
||||
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()) {
|
||||
return;
|
||||
}
|
||||
@ -84,7 +84,7 @@ template <typename SampleSource> class LowpassSpeaker: public Speaker {
|
||||
Sets the clock rate of the input audio.
|
||||
*/
|
||||
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) {
|
||||
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.
|
||||
*/
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
@ -141,7 +141,7 @@ template <typename SampleSource> class LowpassSpeaker: public Speaker {
|
||||
|
||||
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_.parameters_are_dirty = false;
|
||||
filter_parameters_.input_rate_changed = false;
|
||||
|
@ -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::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);
|
||||
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.
|
||||
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) {
|
||||
file_.seek(file_offset(pair.first), SEEK_SET);
|
||||
file_.write(pair.second);
|
||||
|
@ -58,7 +58,7 @@ uint16_t HFE::seek_track(Track::Address address) {
|
||||
std::shared_ptr<Track> HFE::get_track_at_position(Track::Address address) {
|
||||
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);
|
||||
|
||||
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) {
|
||||
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);
|
||||
lock_guard.unlock();
|
||||
|
||||
|
@ -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);
|
||||
|
||||
{
|
||||
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_.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_);
|
||||
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_.seek(file_offset, SEEK_SET);
|
||||
file_.write(parsed_track, sizeof(parsed_track));
|
||||
|
@ -169,7 +169,7 @@ std::shared_ptr<::Storage::Disk::Track> MacintoshIMG::get_track_at_position(::St
|
||||
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) {
|
||||
// Perform a GCR encoding.
|
||||
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.
|
||||
{
|
||||
std::lock_guard<decltype(buffer_mutex_)> buffer_lock(buffer_mutex_);
|
||||
std::lock_guard buffer_lock(buffer_mutex_);
|
||||
for(const auto &pair: tracks_by_address) {
|
||||
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);
|
||||
@ -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.
|
||||
{
|
||||
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_) {
|
||||
// Just dump out the new sectors. Grossly lazy, possibly worth improving.
|
||||
|
@ -61,7 +61,7 @@ std::shared_ptr<::Storage::Disk::Track> NIB::get_track_at_position(::Storage::Di
|
||||
long offset = file_offset(address);
|
||||
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);
|
||||
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.
|
||||
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) {
|
||||
file_.seek(file_offset(track.first), SEEK_SET);
|
||||
file_.write(track.second);
|
||||
|
@ -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) {
|
||||
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);
|
||||
|
||||
// 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);
|
||||
|
||||
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);
|
||||
std::size_t track_size = std::min(size_t(6400), parsed_track.size());
|
||||
file_.write(parsed_track.data(), track_size);
|
||||
|
@ -110,7 +110,7 @@ std::shared_ptr<Track> WOZ::get_track_at_position(Track::Address address) {
|
||||
std::vector<uint8_t> track_contents;
|
||||
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);
|
||||
|
||||
// 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_);
|
||||
|
||||
// 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_.put_le(crc);
|
||||
file_.write(post_crc_contents_);
|
||||
|
Loading…
Reference in New Issue
Block a user