[banshee] GStreamerSharp: convert some Monitor calls into a lock{} block
- From: Andrés Aragoneses <aaragoneses src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [banshee] GStreamerSharp: convert some Monitor calls into a lock{} block
- Date: Tue, 29 Oct 2013 22:02:20 +0000 (UTC)
commit 4b22a04a10828773da5306befdda99809ef5b4c0
Author: Andrés G. Aragoneses <knocte gmail com>
Date: Tue Oct 29 22:59:27 2013 +0100
GStreamerSharp: convert some Monitor calls into a lock{} block
There was some synchronization-related Monitor.{Enter|Exit} calls here,
which can be translated to a lock(){} block, which is:
- Better syntax, as it avoids the fact that you could forget the call
to Monitor.Exit().
- Better protection against exceptions, as the Monitor.Exit() call that
is generated by the lock's syntactic sugar is inside a finally{} block.
The original author of this code probably thought that it was better to
use two Monitor.Exit() calls in order to exit the synchronized region as
soon as possible, but using a return statement inside a lock{} block for
bailing out early is also possible.
.../Banshee.GStreamerSharp/VideoManager.cs | 42 +++++++++----------
1 files changed, 20 insertions(+), 22 deletions(-)
---
diff --git a/src/Backends/Banshee.GStreamerSharp/Banshee.GStreamerSharp/VideoManager.cs
b/src/Backends/Banshee.GStreamerSharp/Banshee.GStreamerSharp/VideoManager.cs
index e44fd61..b6f7bc5 100644
--- a/src/Backends/Banshee.GStreamerSharp/Banshee.GStreamerSharp/VideoManager.cs
+++ b/src/Backends/Banshee.GStreamerSharp/Banshee.GStreamerSharp/VideoManager.cs
@@ -27,7 +27,6 @@
//
using System;
-using System.Threading;
using System.Runtime.InteropServices;
using Mono.Unix;
@@ -125,35 +124,34 @@ namespace Banshee.GStreamerSharp
video_sink = playbin.VideoSink;
- Monitor.Enter (video_mutex);
+ lock (video_mutex) {
- if (video_sink == null) {
- xoverlay = null;
- Monitor.Exit (video_mutex);
- return false;
- }
+ if (video_sink == null) {
+ xoverlay = null;
+ return false;
+ }
- xoverlay_element = video_sink is Bin
- ? ((Bin)video_sink).GetByInterface (new XOverlayAdapter ().GType)
- : video_sink;
+ xoverlay_element = video_sink is Bin
+ ? ((Bin)video_sink).GetByInterface (new XOverlayAdapter ().GType)
+ : video_sink;
- xoverlay = new XOverlayAdapter (xoverlay_element.Handle);
+ xoverlay = new XOverlayAdapter (xoverlay_element.Handle);
- if (!PlatformDetection.IsWindows) {
- // We can't rely on aspect ratio from dshowvideosink
- if (xoverlay != null && xoverlay_element.HasProperty ("force-aspect-ratio")) {
- xoverlay_element ["force-aspect-ratio"] = true;
+ if (!PlatformDetection.IsWindows) {
+ // We can't rely on aspect ratio from dshowvideosink
+ if (xoverlay != null && xoverlay_element.HasProperty ("force-aspect-ratio")) {
+ xoverlay_element ["force-aspect-ratio"] = true;
+ }
}
- }
- if (xoverlay != null && xoverlay_element.HasProperty ("handle-events")) {
- xoverlay_element ["handle-events"] = false;
- }
+ if (xoverlay != null && xoverlay_element.HasProperty ("handle-events")) {
+ xoverlay_element ["handle-events"] = false;
+ }
- found_xoverlay = (xoverlay != null) ? true : false;
+ found_xoverlay = (xoverlay != null) ? true : false;
- Monitor.Exit (video_mutex);
- return found_xoverlay;
+ return found_xoverlay;
+ }
}
public void ParseStreamInfo ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]