From b44bf7cfce6a5aaffbcd1e37df39068a163438ad Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 28 Dec 2018 10:48:14 +0100 Subject: [PATCH] Move from unique_lock to lock_guard everywhere we can. Perhaps ever so slightly clearer to read the intent. --- futatabi/jpeg_frame_view.cpp | 8 ++++---- futatabi/player.cpp | 6 +++--- futatabi/video_stream.cpp | 14 ++++++------- futatabi/video_stream.h | 2 +- nageru/audio_mixer.h | 16 +++++++-------- nageru/compression_reduction_meter.cpp | 2 +- nageru/compression_reduction_meter.h | 2 +- nageru/correlation_meter.cpp | 2 +- nageru/correlation_meter.h | 2 +- nageru/decklink_output.cpp | 2 +- nageru/image_input.cpp | 8 ++++---- nageru/lrameter.cpp | 2 +- nageru/lrameter.h | 2 +- nageru/mixer.cpp | 22 ++++++++++---------- nageru/nageru_cef_app.cpp | 2 +- nageru/pbo_frame_allocator.cpp | 4 ++-- nageru/quicksync_encoder.cpp | 24 +++++++++++----------- nageru/theme.cpp | 28 +++++++++++++------------- nageru/vumeter.cpp | 2 +- nageru/vumeter.h | 4 ++-- shared/httpd.cpp | 10 ++++----- 21 files changed, 82 insertions(+), 82 deletions(-) diff --git a/futatabi/jpeg_frame_view.cpp b/futatabi/jpeg_frame_view.cpp index 2f43517..1924a54 100644 --- a/futatabi/jpeg_frame_view.cpp +++ b/futatabi/jpeg_frame_view.cpp @@ -236,7 +236,7 @@ shared_ptr decode_jpeg_with_cache(FrameOnDisk frame_spec, CacheMissBehavi { *did_decode = false; { - unique_lock lock(cache_mu); + lock_guard lock(cache_mu); auto it = cache.find(frame_spec); if (it != cache.end()) { ++metric_jpeg_cache_hit_frames; @@ -255,7 +255,7 @@ shared_ptr decode_jpeg_with_cache(FrameOnDisk frame_spec, CacheMissBehavi *did_decode = true; shared_ptr frame = decode_jpeg(frame_reader->read_frame(frame_spec)); - unique_lock lock(cache_mu); + lock_guard lock(cache_mu); cache_bytes_used += frame_size(*frame); metric_jpeg_cache_used_bytes = cache_bytes_used; cache[frame_spec] = LRUFrame{ frame, event_counter++ }; @@ -368,7 +368,7 @@ void JPEGFrameView::setFrame(unsigned stream_idx, FrameOnDisk frame, FrameOnDisk { current_stream_idx = stream_idx; // TODO: Does this interact with fades? - unique_lock lock(cache_mu); + lock_guard lock(cache_mu); PendingDecode decode; decode.primary = frame; decode.secondary = secondary_frame; @@ -380,7 +380,7 @@ void JPEGFrameView::setFrame(unsigned stream_idx, FrameOnDisk frame, FrameOnDisk void JPEGFrameView::setFrame(shared_ptr frame) { - unique_lock lock(cache_mu); + lock_guard lock(cache_mu); PendingDecode decode; decode.frame = std::move(frame); decode.destination = this; diff --git a/futatabi/player.cpp b/futatabi/player.cpp index b7ceb03..b871fa1 100644 --- a/futatabi/player.cpp +++ b/futatabi/player.cpp @@ -440,7 +440,7 @@ void Player::override_angle(unsigned stream_idx) // Corner case: If a new clip is waiting to be played, change its stream and then we're done. { - unique_lock lock(queue_state_mu); + lock_guard lock(queue_state_mu); if (new_clip_ready) { assert(queued_clip_list.size() == 1); queued_clip_list[0].stream_idx = stream_idx; @@ -474,13 +474,13 @@ void Player::override_angle(unsigned stream_idx) void Player::take_queue_spot() { - unique_lock lock(queue_state_mu); + lock_guard lock(queue_state_mu); ++num_queued_frames; } void Player::release_queue_spot() { - unique_lock lock(queue_state_mu); + lock_guard lock(queue_state_mu); assert(num_queued_frames > 0); --num_queued_frames; new_clip_changed.notify_all(); diff --git a/futatabi/video_stream.cpp b/futatabi/video_stream.cpp index dcf44f8..7c2f8f9 100644 --- a/futatabi/video_stream.cpp +++ b/futatabi/video_stream.cpp @@ -282,7 +282,7 @@ void VideoStream::clear_queue() deque q; { - unique_lock lock(queue_lock); + lock_guard lock(queue_lock); q = move(frame_queue); } @@ -323,7 +323,7 @@ void VideoStream::schedule_original_frame(steady_clock::time_point local_pts, qf.display_func = move(display_func); qf.queue_spot_holder = move(queue_spot_holder); - unique_lock lock(queue_lock); + lock_guard lock(queue_lock); frame_queue.push_back(move(qf)); queue_changed.notify_all(); } @@ -342,7 +342,7 @@ void VideoStream::schedule_faded_frame(steady_clock::time_point local_pts, int64 // separate pools around.) BorrowedInterpolatedFrameResources resources; { - unique_lock lock(queue_lock); + lock_guard lock(queue_lock); if (interpolate_resources.empty()) { fprintf(stderr, "WARNING: Too many interpolated frames already in transit; dropping one.\n"); return; @@ -391,7 +391,7 @@ void VideoStream::schedule_faded_frame(steady_clock::time_point local_pts, int64 qf.resources = move(resources); qf.local_pts = local_pts; - unique_lock lock(queue_lock); + lock_guard lock(queue_lock); frame_queue.push_back(move(qf)); queue_changed.notify_all(); } @@ -411,7 +411,7 @@ void VideoStream::schedule_interpolated_frame(steady_clock::time_point local_pts // Get the temporary OpenGL resources we need for doing the interpolation. BorrowedInterpolatedFrameResources resources; { - unique_lock lock(queue_lock); + lock_guard lock(queue_lock); if (interpolate_resources.empty()) { fprintf(stderr, "WARNING: Too many interpolated frames already in transit; dropping one.\n"); return; @@ -517,7 +517,7 @@ void VideoStream::schedule_interpolated_frame(steady_clock::time_point local_pts check_error(); qf.resources = move(resources); - unique_lock lock(queue_lock); + lock_guard lock(queue_lock); frame_queue.push_back(move(qf)); queue_changed.notify_all(); } @@ -532,7 +532,7 @@ void VideoStream::schedule_refresh_frame(steady_clock::time_point local_pts, qf.display_func = move(display_func); qf.queue_spot_holder = move(queue_spot_holder); - unique_lock lock(queue_lock); + lock_guard lock(queue_lock); frame_queue.push_back(move(qf)); queue_changed.notify_all(); } diff --git a/futatabi/video_stream.h b/futatabi/video_stream.h index 422b152..05bd7a7 100644 --- a/futatabi/video_stream.h +++ b/futatabi/video_stream.h @@ -99,7 +99,7 @@ private: void operator() (InterpolatedFrameResources *ifr) const { if (ifr != nullptr) { - std::unique_lock lock(ifr->owner->queue_lock); + std::lock_guard lock(ifr->owner->queue_lock); ifr->owner->interpolate_resources.emplace_back(ifr); } } diff --git a/nageru/audio_mixer.h b/nageru/audio_mixer.h index a7ab9a5..e435b46 100644 --- a/nageru/audio_mixer.h +++ b/nageru/audio_mixer.h @@ -208,51 +208,51 @@ public: void set_gain_staging_db(unsigned bus_index, float gain_db) { - std::unique_lock lock(compressor_mutex); + std::lock_guard lock(compressor_mutex); level_compressor_enabled[bus_index] = false; gain_staging_db[bus_index] = gain_db; } float get_gain_staging_db(unsigned bus_index) const { - std::unique_lock lock(compressor_mutex); + std::lock_guard lock(compressor_mutex); return gain_staging_db[bus_index]; } void set_gain_staging_auto(unsigned bus_index, bool enabled) { - std::unique_lock lock(compressor_mutex); + std::lock_guard lock(compressor_mutex); level_compressor_enabled[bus_index] = enabled; } bool get_gain_staging_auto(unsigned bus_index) const { - std::unique_lock lock(compressor_mutex); + std::lock_guard lock(compressor_mutex); return level_compressor_enabled[bus_index]; } void set_final_makeup_gain_db(float gain_db) { - std::unique_lock lock(compressor_mutex); + std::lock_guard lock(compressor_mutex); final_makeup_gain_auto = false; final_makeup_gain = from_db(gain_db); } float get_final_makeup_gain_db() { - std::unique_lock lock(compressor_mutex); + std::lock_guard lock(compressor_mutex); return to_db(final_makeup_gain); } void set_final_makeup_gain_auto(bool enabled) { - std::unique_lock lock(compressor_mutex); + std::lock_guard lock(compressor_mutex); final_makeup_gain_auto = enabled; } bool get_final_makeup_gain_auto() const { - std::unique_lock lock(compressor_mutex); + std::lock_guard lock(compressor_mutex); return final_makeup_gain_auto; } diff --git a/nageru/compression_reduction_meter.cpp b/nageru/compression_reduction_meter.cpp index a59a71e..d123260 100644 --- a/nageru/compression_reduction_meter.cpp +++ b/nageru/compression_reduction_meter.cpp @@ -41,7 +41,7 @@ void CompressionReductionMeter::paintEvent(QPaintEvent *event) float level_db; { - unique_lock lock(level_mutex); + lock_guard lock(level_mutex); level_db = this->level_db; } diff --git a/nageru/compression_reduction_meter.h b/nageru/compression_reduction_meter.h index 5890c13..ac5a840 100644 --- a/nageru/compression_reduction_meter.h +++ b/nageru/compression_reduction_meter.h @@ -23,7 +23,7 @@ public: CompressionReductionMeter(QWidget *parent); void set_reduction_db(float level_db) { - std::unique_lock lock(level_mutex); + std::lock_guard lock(level_mutex); this->level_db = level_db; QMetaObject::invokeMethod(this, "update", Qt::AutoConnection); } diff --git a/nageru/correlation_meter.cpp b/nageru/correlation_meter.cpp index 7b7683a..7246745 100644 --- a/nageru/correlation_meter.cpp +++ b/nageru/correlation_meter.cpp @@ -47,7 +47,7 @@ void CorrelationMeter::paintEvent(QPaintEvent *event) float correlation; { - unique_lock lock(correlation_mutex); + lock_guard lock(correlation_mutex); correlation = this->correlation; } diff --git a/nageru/correlation_meter.h b/nageru/correlation_meter.h index ea01e04..fa92aec 100644 --- a/nageru/correlation_meter.h +++ b/nageru/correlation_meter.h @@ -19,7 +19,7 @@ public: CorrelationMeter(QWidget *parent); void set_correlation(float correlation) { - std::unique_lock lock(correlation_mutex); + std::lock_guard lock(correlation_mutex); this->correlation = correlation; QMetaObject::invokeMethod(this, "update", Qt::AutoConnection); } diff --git a/nageru/decklink_output.cpp b/nageru/decklink_output.cpp index bd59b32..ed66212 100644 --- a/nageru/decklink_output.cpp +++ b/nageru/decklink_output.cpp @@ -317,7 +317,7 @@ void DeckLinkOutput::send_frame(GLuint y_tex, GLuint cbcr_tex, YCbCrLumaCoeffici frame->duration = duration; { - unique_lock lock(frame_queue_mutex); + lock_guard lock(frame_queue_mutex); pending_video_frames.push(move(frame)); } frame_queues_changed.notify_all(); diff --git a/nageru/image_input.cpp b/nageru/image_input.cpp index 5f69570..4b6840b 100644 --- a/nageru/image_input.cpp +++ b/nageru/image_input.cpp @@ -63,7 +63,7 @@ void ImageInput::set_gl_state(GLuint glsl_program_num, const string& prefix, uns // so there's a fair amount of OpenGL memory waste anyway (the cache // is mostly there to save startup time, not RAM). { - unique_lock lock(all_images_lock); + lock_guard lock(all_images_lock); if (all_images[pathname] != current_image) { current_image = all_images[pathname]; set_pixel_data(current_image->pixels.get()); @@ -74,7 +74,7 @@ void ImageInput::set_gl_state(GLuint glsl_program_num, const string& prefix, uns shared_ptr ImageInput::load_image(const string &filename, const string &pathname) { - unique_lock lock(all_images_lock); // Held also during loading. + lock_guard lock(all_images_lock); // Held also during loading. if (all_images.count(pathname)) { return all_images[pathname]; } @@ -234,7 +234,7 @@ void ImageInput::update_thread_func(const std::string &filename, const std::stri continue; } fprintf(stderr, "Loaded new version of %s from disk.\n", pathname.c_str()); - unique_lock lock(all_images_lock); + lock_guard lock(all_images_lock); all_images[pathname] = image; last_modified = image->last_modified; } @@ -243,7 +243,7 @@ void ImageInput::update_thread_func(const std::string &filename, const std::stri void ImageInput::shutdown_updaters() { { - unique_lock lock(threads_should_quit_mu); + lock_guard lock(threads_should_quit_mu); threads_should_quit = true; threads_should_quit_modified.notify_all(); } diff --git a/nageru/lrameter.cpp b/nageru/lrameter.cpp index 62b4a9f..087a40e 100644 --- a/nageru/lrameter.cpp +++ b/nageru/lrameter.cpp @@ -30,7 +30,7 @@ void LRAMeter::paintEvent(QPaintEvent *event) float range_low_lufs; float range_high_lufs; { - unique_lock lock(level_mutex); + lock_guard lock(level_mutex); level_lufs = this->level_lufs; range_low_lufs = this->range_low_lufs; range_high_lufs = this->range_high_lufs; diff --git a/nageru/lrameter.h b/nageru/lrameter.h index 7a832df..f4cca82 100644 --- a/nageru/lrameter.h +++ b/nageru/lrameter.h @@ -21,7 +21,7 @@ public: LRAMeter(QWidget *parent); void set_levels(float level_lufs, float range_low_lufs, float range_high_lufs) { - std::unique_lock lock(level_mutex); + std::lock_guard lock(level_mutex); this->level_lufs = level_lufs; this->range_low_lufs = range_low_lufs; this->range_high_lufs = range_high_lufs; diff --git a/nageru/mixer.cpp b/nageru/mixer.cpp index c25b22d..23ad514 100644 --- a/nageru/mixer.cpp +++ b/nageru/mixer.cpp @@ -829,7 +829,7 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode, // Still send on the information that we _had_ a frame, even though it's corrupted, // so that pts can go up accordingly. { - unique_lock lock(card_mutex); + lock_guard lock(card_mutex); CaptureCard::NewFrame new_frame; new_frame.frame = RefCountedFrame(FrameAllocator::Frame()); new_frame.length = frame_length; @@ -953,7 +953,7 @@ void Mixer::bm_frame(unsigned card_index, uint16_t timecode, } { - unique_lock lock(card_mutex); + lock_guard lock(card_mutex); CaptureCard::NewFrame new_frame; new_frame.frame = frame; new_frame.length = frame_length; @@ -1348,7 +1348,7 @@ void Mixer::schedule_audio_resampling_tasks(unsigned dropped_frames, int num_sam // non-dropped frame; perhaps we should just discard that as well, // since dropped frames are expected to be rare, and it might be // better to just wait until we have a slightly more normal situation). - unique_lock lock(audio_mutex); + lock_guard lock(audio_mutex); bool adjust_rate = !dropped_frame && !is_preroll; audio_task_queue.push(AudioTask{pts_int, num_samples_per_frame, adjust_rate, frame_timestamp}); audio_task_queue_changed.notify_one(); @@ -1372,7 +1372,7 @@ void Mixer::render_one_frame(int64_t duration) // Update Y'CbCr settings for all cards. { - unique_lock lock(card_mutex); + lock_guard lock(card_mutex); for (unsigned card_index = 0; card_index < num_cards; ++card_index) { YCbCrInterpretation *interpretation = &ycbcr_interpretation[card_index]; input_state.ycbcr_coefficients_auto[card_index] = interpretation->ycbcr_coefficients_auto; @@ -1578,13 +1578,13 @@ void Mixer::channel_clicked(int preview_num) YCbCrInterpretation Mixer::get_input_ycbcr_interpretation(unsigned card_index) const { - unique_lock lock(card_mutex); + lock_guard lock(card_mutex); return ycbcr_interpretation[card_index]; } void Mixer::set_input_ycbcr_interpretation(unsigned card_index, const YCbCrInterpretation &interpretation) { - unique_lock lock(card_mutex); + lock_guard lock(card_mutex); ycbcr_interpretation[card_index] = interpretation; } @@ -1608,7 +1608,7 @@ void Mixer::start_mode_scanning(unsigned card_index) map Mixer::get_available_output_video_modes() const { assert(desired_output_card_index != -1); - unique_lock lock(card_mutex); + lock_guard lock(card_mutex); return cards[desired_output_card_index].output->get_available_video_modes(); } @@ -1646,7 +1646,7 @@ void Mixer::OutputChannel::output_frame(DisplayFrame &&frame) // Store this frame for display. Remove the ready frame if any // (it was seemingly never used). { - unique_lock lock(frame_mutex); + lock_guard lock(frame_mutex); if (has_ready_frame) { parent->release_display_frame(&ready_frame); } @@ -1701,7 +1701,7 @@ void Mixer::OutputChannel::output_frame(DisplayFrame &&frame) bool Mixer::OutputChannel::get_display_frame(DisplayFrame *frame) { - unique_lock lock(frame_mutex); + lock_guard lock(frame_mutex); if (!has_current_frame && !has_ready_frame) { return false; } @@ -1726,13 +1726,13 @@ bool Mixer::OutputChannel::get_display_frame(DisplayFrame *frame) void Mixer::OutputChannel::add_frame_ready_callback(void *key, Mixer::new_frame_ready_callback_t callback) { - unique_lock lock(frame_mutex); + lock_guard lock(frame_mutex); new_frame_ready_callbacks[key] = callback; } void Mixer::OutputChannel::remove_frame_ready_callback(void *key) { - unique_lock lock(frame_mutex); + lock_guard lock(frame_mutex); new_frame_ready_callbacks.erase(key); } diff --git a/nageru/nageru_cef_app.cpp b/nageru/nageru_cef_app.cpp index 2e64cee..edda9b2 100644 --- a/nageru/nageru_cef_app.cpp +++ b/nageru/nageru_cef_app.cpp @@ -29,7 +29,7 @@ void NageruCefApp::initialize_cef() void NageruCefApp::close_browser(CefRefPtr browser) { - unique_lock lock(cef_mutex); + lock_guard lock(cef_mutex); browser->GetHost()->CloseBrowser(/*force_close=*/true); } diff --git a/nageru/pbo_frame_allocator.cpp b/nageru/pbo_frame_allocator.cpp index c868702..6211937 100644 --- a/nageru/pbo_frame_allocator.cpp +++ b/nageru/pbo_frame_allocator.cpp @@ -261,7 +261,7 @@ bmusb::FrameAllocator::Frame PBOFrameAllocator::alloc_frame() { Frame vf; - unique_lock lock(freelist_mutex); // Meh. + lock_guard lock(freelist_mutex); // Meh. if (freelist.empty()) { printf("Frame overrun (no more spare PBO frames), dropping frame!\n"); } else { @@ -309,7 +309,7 @@ void PBOFrameAllocator::release_frame(Frame frame) } #endif - unique_lock lock(freelist_mutex); + lock_guard lock(freelist_mutex); freelist.push(frame); //--sumsum; } diff --git a/nageru/quicksync_encoder.cpp b/nageru/quicksync_encoder.cpp index 4d53b0b..4883554 100644 --- a/nageru/quicksync_encoder.cpp +++ b/nageru/quicksync_encoder.cpp @@ -1023,7 +1023,7 @@ void QuickSyncEncoderImpl::update_ReferenceFrames(int current_display_frame, int pic_param.CurrPic.frame_idx = current_ref_frame_num; CurrentCurrPic.flags = VA_PICTURE_H264_SHORT_TERM_REFERENCE; - unique_lock lock(storage_task_queue_mutex); + lock_guard lock(storage_task_queue_mutex); // Insert the new frame at the start of the reference queue. reference_frames.push_front(ReferenceFrame{ CurrentCurrPic, current_display_frame }); @@ -1434,7 +1434,7 @@ void QuickSyncEncoderImpl::save_codeddata(GLSurface *surf, storage_task task) // this is weird. but it seems to put a new frame onto the queue void QuickSyncEncoderImpl::storage_task_enqueue(storage_task task) { - unique_lock lock(storage_task_queue_mutex); + lock_guard lock(storage_task_queue_mutex); storage_task_queue.push(move(task)); storage_task_queue_changed.notify_all(); } @@ -1468,7 +1468,7 @@ void QuickSyncEncoderImpl::storage_task_thread() // Unlock the frame, and all its references. { - unique_lock lock(storage_task_queue_mutex); + lock_guard lock(storage_task_queue_mutex); release_gl_surface(display_order); for (size_t frame_num : ref_display_frame_numbers) { @@ -1706,7 +1706,7 @@ RefCountedGLsync QuickSyncEncoderImpl::end_frame() GLenum type = global_flags.x264_bit_depth > 8 ? GL_UNSIGNED_SHORT : GL_UNSIGNED_BYTE; GLSurface *surf; { - unique_lock lock(storage_task_queue_mutex); + lock_guard lock(storage_task_queue_mutex); surf = surface_for_frame[current_storage_frame]; assert(surf != nullptr); } @@ -1745,7 +1745,7 @@ RefCountedGLsync QuickSyncEncoderImpl::end_frame() check_error(); { - unique_lock lock(frame_queue_mutex); + lock_guard lock(frame_queue_mutex); current_video_frame.fence = fence; pending_video_frames.push(move(current_video_frame)); ++current_storage_frame; @@ -1761,13 +1761,13 @@ void QuickSyncEncoderImpl::shutdown() } { - unique_lock lock(frame_queue_mutex); + lock_guard lock(frame_queue_mutex); encode_thread_should_quit = true; frame_queue_nonempty.notify_all(); } encode_thread.join(); { - unique_lock lock(storage_task_queue_mutex); + lock_guard lock(storage_task_queue_mutex); storage_thread_should_quit = true; frame_queue_nonempty.notify_all(); storage_task_queue_changed.notify_all(); @@ -1864,7 +1864,7 @@ void QuickSyncEncoderImpl::encode_thread_func() pass_frame(frame, display_frame_num, frame.pts, frame.duration); if (global_flags.x264_video_to_disk) { - unique_lock lock(storage_task_queue_mutex); + lock_guard lock(storage_task_queue_mutex); release_gl_surface(display_frame_num); continue; } @@ -1887,7 +1887,7 @@ void QuickSyncEncoderImpl::encode_thread_func() if (frame_type == FRAME_IDR) { // Release any reference frames from the previous GOP. { - unique_lock lock(storage_task_queue_mutex); + lock_guard lock(storage_task_queue_mutex); for (const ReferenceFrame &frame : reference_frames) { release_gl_surface(frame.display_number); } @@ -1980,7 +1980,7 @@ void QuickSyncEncoderImpl::pass_frame(QuickSyncEncoderImpl::PendingFrame frame, GLSurface *surf; { - unique_lock lock(storage_task_queue_mutex); + lock_guard lock(storage_task_queue_mutex); surf = surface_for_frame[display_frame_num]; assert(surf != nullptr); } @@ -1999,7 +1999,7 @@ void QuickSyncEncoderImpl::encode_frame(QuickSyncEncoderImpl::PendingFrame frame GLSurface *surf; { - unique_lock lock(storage_task_queue_mutex); + lock_guard lock(storage_task_queue_mutex); surf = surface_for_frame[display_frame_num]; assert(surf != nullptr); } @@ -2063,7 +2063,7 @@ void QuickSyncEncoderImpl::encode_frame(QuickSyncEncoderImpl::PendingFrame frame // Lock the references for this frame; otherwise, they could be // rendered to before this frame is done encoding. { - unique_lock lock(storage_task_queue_mutex); + lock_guard lock(storage_task_queue_mutex); for (const ReferenceFrame &frame : reference_frames) { assert(surface_for_frame.count(frame.display_number)); ++surface_for_frame[frame.display_number]->refcount; diff --git a/nageru/theme.cpp b/nageru/theme.cpp index d28f5b2..386a425 100644 --- a/nageru/theme.cpp +++ b/nageru/theme.cpp @@ -100,7 +100,7 @@ class LuaRefWithDeleter { public: LuaRefWithDeleter(mutex *m, lua_State *L, int ref) : m(m), L(L), ref(ref) {} ~LuaRefWithDeleter() { - unique_lock lock(*m); + lock_guard lock(*m); luaL_unref(L, LUA_REGISTRYINDEX, ref); } int get() const { return ref; } @@ -1221,7 +1221,7 @@ Theme::Chain Theme::get_chain(unsigned num, float t, unsigned width, unsigned he { Chain chain; - unique_lock lock(m); + lock_guard lock(m); assert(lua_gettop(L) == 0); lua_getglobal(L, "get_chain"); /* function to be called */ lua_pushnumber(L, num); @@ -1252,7 +1252,7 @@ Theme::Chain Theme::get_chain(unsigned num, float t, unsigned width, unsigned he assert(lua_gettop(L) == 0); chain.setup_chain = [this, funcref, input_state, effect_chain]{ - unique_lock lock(m); + lock_guard lock(m); assert(this->input_state == nullptr); this->input_state = &input_state; @@ -1297,7 +1297,7 @@ Theme::Chain Theme::get_chain(unsigned num, float t, unsigned width, unsigned he string Theme::get_channel_name(unsigned channel) { - unique_lock lock(m); + lock_guard lock(m); lua_getglobal(L, "channel_name"); lua_pushnumber(L, channel); if (lua_pcall(L, 1, 1, 0) != 0) { @@ -1318,7 +1318,7 @@ string Theme::get_channel_name(unsigned channel) int Theme::get_channel_signal(unsigned channel) { - unique_lock lock(m); + lock_guard lock(m); lua_getglobal(L, "channel_signal"); lua_pushnumber(L, channel); if (lua_pcall(L, 1, 1, 0) != 0) { @@ -1334,7 +1334,7 @@ int Theme::get_channel_signal(unsigned channel) std::string Theme::get_channel_color(unsigned channel) { - unique_lock lock(m); + lock_guard lock(m); lua_getglobal(L, "channel_color"); lua_pushnumber(L, channel); if (lua_pcall(L, 1, 1, 0) != 0) { @@ -1356,7 +1356,7 @@ std::string Theme::get_channel_color(unsigned channel) bool Theme::get_supports_set_wb(unsigned channel) { - unique_lock lock(m); + lock_guard lock(m); lua_getglobal(L, "supports_set_wb"); lua_pushnumber(L, channel); if (lua_pcall(L, 1, 1, 0) != 0) { @@ -1372,7 +1372,7 @@ bool Theme::get_supports_set_wb(unsigned channel) void Theme::set_wb(unsigned channel, double r, double g, double b) { - unique_lock lock(m); + lock_guard lock(m); lua_getglobal(L, "set_wb"); lua_pushnumber(L, channel); lua_pushnumber(L, r); @@ -1388,7 +1388,7 @@ void Theme::set_wb(unsigned channel, double r, double g, double b) vector Theme::get_transition_names(float t) { - unique_lock lock(m); + lock_guard lock(m); lua_getglobal(L, "get_transitions"); lua_pushnumber(L, t); if (lua_pcall(L, 1, 1, 0) != 0) { @@ -1414,7 +1414,7 @@ int Theme::map_signal(int signal_num) return -1 - signal_num; } - unique_lock lock(map_m); + lock_guard lock(map_m); if (signal_to_card_mapping.count(signal_num)) { return signal_to_card_mapping[signal_num]; } @@ -1444,14 +1444,14 @@ int Theme::map_signal(int signal_num) void Theme::set_signal_mapping(int signal_num, int card_num) { - unique_lock lock(map_m); + lock_guard lock(map_m); assert(card_num < int(num_cards)); signal_to_card_mapping[signal_num] = card_num; } void Theme::transition_clicked(int transition_num, float t) { - unique_lock lock(m); + lock_guard lock(m); lua_getglobal(L, "transition_clicked"); lua_pushnumber(L, transition_num); lua_pushnumber(L, t); @@ -1465,7 +1465,7 @@ void Theme::transition_clicked(int transition_num, float t) void Theme::channel_clicked(int preview_num) { - unique_lock lock(m); + lock_guard lock(m); lua_getglobal(L, "channel_clicked"); lua_pushnumber(L, preview_num); @@ -1507,7 +1507,7 @@ int Theme::set_theme_menu(lua_State *L) void Theme::theme_menu_entry_clicked(int lua_ref) { - unique_lock lock(m); + lock_guard lock(m); lua_rawgeti(L, LUA_REGISTRYINDEX, lua_ref); if (lua_pcall(L, 0, 0, 0) != 0) { fprintf(stderr, "error running menu callback: %s\n", lua_tostring(L, -1)); diff --git a/nageru/vumeter.cpp b/nageru/vumeter.cpp index b697a83..228d2c2 100644 --- a/nageru/vumeter.cpp +++ b/nageru/vumeter.cpp @@ -25,7 +25,7 @@ void VUMeter::paintEvent(QPaintEvent *event) float level_lufs[2], peak_lufs[2]; { - unique_lock lock(level_mutex); + lock_guard lock(level_mutex); level_lufs[0] = this->level_lufs[0]; level_lufs[1] = this->level_lufs[1]; peak_lufs[0] = this->peak_lufs[0]; diff --git a/nageru/vumeter.h b/nageru/vumeter.h index 7a94200..f58eeff 100644 --- a/nageru/vumeter.h +++ b/nageru/vumeter.h @@ -25,7 +25,7 @@ public: } void set_level(float level_lufs_left, float level_lufs_right) { - std::unique_lock lock(level_mutex); + std::lock_guard lock(level_mutex); this->level_lufs[0] = level_lufs_left; this->level_lufs[1] = level_lufs_right; QMetaObject::invokeMethod(this, "update", Qt::AutoConnection); @@ -36,7 +36,7 @@ public: } void set_peak(float peak_lufs_left, float peak_lufs_right) { - std::unique_lock lock(level_mutex); + std::lock_guard lock(level_mutex); this->peak_lufs[0] = peak_lufs_left; this->peak_lufs[1] = peak_lufs_right; QMetaObject::invokeMethod(this, "update", Qt::AutoConnection); diff --git a/shared/httpd.cpp b/shared/httpd.cpp index 782d18b..5442e7f 100644 --- a/shared/httpd.cpp +++ b/shared/httpd.cpp @@ -61,7 +61,7 @@ void HTTPD::stop() void HTTPD::add_data(StreamType stream_type, const char *buf, size_t size, bool keyframe, int64_t time, AVRational timebase) { - unique_lock lock(streams_mutex); + lock_guard lock(streams_mutex); for (Stream *stream : streams) { if (stream->get_stream_type() == stream_type) { stream->add_data(buf, size, keyframe ? Stream::DATA_TYPE_KEYFRAME : Stream::DATA_TYPE_OTHER, time, timebase); @@ -133,7 +133,7 @@ int HTTPD::answer_to_connection(MHD_Connection *connection, HTTPD::Stream *stream = new HTTPD::Stream(this, framing, stream_type); stream->add_data(header[stream_type].data(), header[stream_type].size(), Stream::DATA_TYPE_HEADER, AV_NOPTS_VALUE, AVRational{ 1, 0 }); { - unique_lock lock(streams_mutex); + lock_guard lock(streams_mutex); streams.insert(stream); } ++metric_num_connected_clients; @@ -164,7 +164,7 @@ void HTTPD::free_stream(void *cls) --httpd->metric_num_connected_multicam_clients; } { - unique_lock lock(httpd->streams_mutex); + lock_guard lock(httpd->streams_mutex); delete stream; httpd->streams.erase(stream); } @@ -223,7 +223,7 @@ void HTTPD::Stream::add_data(const char *buf, size_t buf_size, HTTPD::Stream::Da return; } - unique_lock lock(buffer_mutex); + lock_guard lock(buffer_mutex); if (framing == FRAMING_METACUBE) { int flags = 0; @@ -284,7 +284,7 @@ void HTTPD::Stream::add_data(const char *buf, size_t buf_size, HTTPD::Stream::Da void HTTPD::Stream::stop() { - unique_lock lock(buffer_mutex); + lock_guard lock(buffer_mutex); should_quit = true; has_buffered_data.notify_all(); } -- 2.39.2