gap-dev-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gap-dev-discuss] Fix crashes when using a threaded backend


From: Philippe Roussel
Subject: [Gap-dev-discuss] Fix crashes when using a threaded backend
Date: Tue, 15 May 2012 13:30:23 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:12.0) Gecko/20120430 Thunderbird/12.0.1

Hi guys,

Could you review the appended patch and apply it if you agree with it ?

With this applied I can't make Cynthiune crash when playing a song and
seeking through it (holding the left mouse button and moving the seeking
knob).

Thanks,
Philippe

Index: ChangeLog
===================================================================
RCS file: /sources/gap/gap/user-apps/Cynthiune/ChangeLog,v
retrieving revision 1.43
diff -u -r1.43 ChangeLog
--- ChangeLog   14 May 2012 17:09:08 -0000      1.43
+++ ChangeLog   15 May 2012 11:24:36 -0000
@@ -1,3 +1,11 @@
+2012-05-15  Philippe Roussel  <address@hidden>
+
+       * Player.m
+       * Player.h
+       Fix crashes when seeking through a file when using a threaded
+       backend. In this case the input stream is accessed from at
+       least two threads and so must be protected by a lock.
+
 2012-05-14 Philippe Roussel

        * Bundles/Timidity/Timidity.m
Index: Player.h
===================================================================
RCS file: /sources/gap/gap/user-apps/Cynthiune/Player.h,v
retrieving revision 1.2
diff -u -r1.2 Player.h
--- Player.h    12 May 2012 22:29:17 -0000      1.2
+++ Player.h    15 May 2012 11:24:36 -0000
@@ -29,6 +29,7 @@

 #import <Cynthiune/Format.h>

address@hidden NSLock;
 @class NSNotification;
 @class NSString;

@@ -43,6 +44,7 @@
   NSObject <Output> *output;
   BOOL outputIsThreaded;

+  NSLock *streamLock;
   NSObject <Format> *stream;

   NSMutableArray *streamsToClose;
Index: Player.m
===================================================================
RCS file: /sources/gap/gap/user-apps/Cynthiune/Player.m,v
retrieving revision 1.2
diff -u -r1.2 Player.m
--- Player.m    12 May 2012 22:29:17 -0000      1.2
+++ Player.m    15 May 2012 11:24:36 -0000
@@ -27,6 +27,7 @@
 #import <Foundation/NSData.h>
 #import <Foundation/NSDate.h>
 #import <Foundation/NSEnumerator.h>
+#import <Foundation/NSLock.h>
 #import <Foundation/NSNotification.h>
 #import <Foundation/NSString.h>
 #import <Foundation/NSThread.h>
@@ -68,6 +69,7 @@
       output = nil;
       outputIsThreaded = NO;
       stream = nil;
+      streamLock = [NSLock new];
       delegate = nil;
       paused = NO;
       playing = NO;
@@ -93,6 +95,7 @@
   if (delegate)
     [nc removeObserver: delegate name: nil object: self];
   [streamsToClose release];
+  [streamLock release];
   [super dealloc];
 }

@@ -246,7 +249,9 @@

   if (!closingThread)
     {
+      [streamLock lock];
       inputSize = [stream readNextChunk: buffer withSize: bufferSize];
+      [streamLock unlock];

       if (inputSize > 0)
         {
@@ -437,7 +442,9 @@

 - (void) seek: (unsigned int) seconds
 {
+  [streamLock lock];
   [stream seek: seconds];
+  [streamLock unlock];
   totalBytes = seconds * rate * channels * 2;
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]