[Scopeapp-cvs]scopeapp/src TraceView.h,1.4,1.5 TraceView.m,1.7,1.8 XYPlotView.m,1.7,1.8 ScopeView.m,
Status: Alpha
Brought to you by:
narge
From: <sco...@li...> - 2003-01-09 04:45:02
|
Update of /cvsroot/scopeapp/scopeapp/src In directory sc8-pr-cvs1:/tmp/cvs-serv18940 Modified Files: TraceView.h TraceView.m XYPlotView.m ScopeView.m Log Message: Improve handling of changes to display settings; fix possible deadlock in draw thread Index: TraceView.h =================================================================== RCS file: /cvsroot/scopeapp/scopeapp/src/TraceView.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TraceView.h 5 Dec 2002 15:08:10 -0000 1.4 --- TraceView.h 9 Jan 2003 04:44:59 -0000 1.5 *************** *** 53,56 **** --- 53,57 ---- NSConditionLock* myDrawThreadState; // semaphore to start & stop the drawing thread BOOL myDisplayIsFrozen; + BOOL myDrawThreadShouldRun; } *************** *** 71,74 **** --- 72,77 ---- atPosition: (unsigned long[2]) outTriggerPos didTrigger: (BOOL[2]) outTriggered; + + - (id) clearData; @end Index: TraceView.m =================================================================== RCS file: /cvsroot/scopeapp/scopeapp/src/TraceView.m,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** TraceView.m 5 Dec 2002 15:08:10 -0000 1.7 --- TraceView.m 9 Jan 2003 04:44:59 -0000 1.8 *************** *** 43,48 **** @interface TraceView (TraceViewInternal) - - (id)clearData; - - (id)cycleBuffers; --- 43,46 ---- *************** *** 80,84 **** { [self stopDrawing]; ! if(mySampler != nil) { [mySampler release]; } [myBezierPaths[0] release]; --- 78,86 ---- { [self stopDrawing]; ! if(mySampler != nil) { ! [mySampler stopSampling]; ! [mySampler setOwner:nil]; ! [mySampler release]; ! } [myBezierPaths[0] release]; *************** *** 150,153 **** --- 152,156 ---- { if(mySampler != nil) { + [mySampler stopSampling]; [mySampler setOwner: nil]; [mySampler release]; *************** *** 157,160 **** --- 160,170 ---- [mySampler setOwner: self]; + mySampleRate = [mySampler sampleRate]; + myChannelCount = [mySampler channelCount]; + + [self updateControls]; + + [mySampler startSampling]; + return [self startDrawing]; } *************** *** 162,168 **** -(id) startDrawing { ! [mySampler startSampling]; ! ! if(![myDrawThreadState tryLockWhenCondition: kDrawThreadStopped]) { return self; } [myDrawThreadState unlockWithCondition: kDrawThreadRunning]; --- 172,180 ---- -(id) startDrawing { ! if(myDrawThreadShouldRun) return self; ! ! myDrawThreadShouldRun = YES; ! ! [myDrawThreadState lockWhenCondition: kDrawThreadStopped]; [myDrawThreadState unlockWithCondition: kDrawThreadRunning]; *************** *** 178,186 **** // tell the thread to stop [myDrawThreadState lock]; [myDrawThreadState unlockWithCondition: kDrawThreadStopped]; ! // stop the sampler ! [mySampler stopSampling]; return self; --- 190,200 ---- // tell the thread to stop + myDrawThreadShouldRun = NO; + + // wait for it to really stop [myDrawThreadState lock]; [myDrawThreadState unlockWithCondition: kDrawThreadStopped]; ! [self clearData]; return self; *************** *** 191,203 **** myDisplayIsFrozen = freeze; ! if(freeze) ! { ! [mySampler stopSampling]; [self clearData]; } ! else ! { ! [mySampler startSampling]; ! } return self; } --- 205,212 ---- myDisplayIsFrozen = freeze; ! if(!freeze) { [self clearData]; } ! return self; } *************** *** 218,222 **** unsigned long theTriggerPoint[2] = { 0, 0 }; int curChannel; ! if(channelCount != myChannelCount || sampleRate != mySampleRate) { --- 227,235 ---- unsigned long theTriggerPoint[2] = { 0, 0 }; int curChannel; ! ! if(myDisplayIsFrozen || [myDrawThreadState condition] == kDrawThreadStopped) { ! return self; ! } ! if(channelCount != myChannelCount || sampleRate != mySampleRate) { *************** *** 285,288 **** --- 298,313 ---- } + - (id)clearData + { + [myDataLock lock]; + + myDataCollected[0] = 0; + myDataCollected[1] = 0; + + [myDataLock unlockWithCondition: kWaitingForData]; + + return self; + } + @end *************** *** 312,332 **** } - - (id)clearData - { - [myDataLock lock]; - - myDataCollected[0] = 0; - myDataCollected[1] = 0; - - [myDataLock unlockWithCondition: kWaitingForData]; - - return self; - } - - (void)displayThread: (id) unused { NSAutoreleasePool *pool; pool = [[NSAutoreleasePool alloc] init]; ! while([myDrawThreadState tryLockWhenCondition: kDrawThreadRunning]) { [myDataLock lockWhenCondition: kHaveRequiredData]; --- 337,348 ---- } - (void)displayThread: (id) unused { NSAutoreleasePool *pool; pool = [[NSAutoreleasePool alloc] init]; ! ! [myDrawThreadState lockWhenCondition: kDrawThreadRunning]; ! ! while(myDrawThreadShouldRun) { [myDataLock lockWhenCondition: kHaveRequiredData]; *************** *** 337,343 **** [self display]; - - [myDrawThreadState unlock]; } } --- 353,359 ---- [self display]; } + + [myDrawThreadState unlock]; } Index: XYPlotView.m =================================================================== RCS file: /cvsroot/scopeapp/scopeapp/src/XYPlotView.m,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** XYPlotView.m 29 Oct 2002 05:50:11 -0000 1.7 --- XYPlotView.m 9 Jan 2003 04:44:59 -0000 1.8 *************** *** 64,69 **** } - [self stopDrawing]; - myXScale = gVoltScales[[myXScaleSlider intValue]-1] * pow(2.0, [myXFineSlider doubleValue]); --- 64,67 ---- *************** *** 71,76 **** myYScale = gVoltScales[[myYScaleSlider intValue]-1] * pow(2.0, [myYFineSlider doubleValue]); - - [self startDrawing]; } --- 69,72 ---- Index: ScopeView.m =================================================================== RCS file: /cvsroot/scopeapp/scopeapp/src/ScopeView.m,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ScopeView.m 5 Dec 2002 15:08:10 -0000 1.14 --- ScopeView.m 9 Jan 2003 04:44:59 -0000 1.15 *************** *** 104,107 **** --- 104,109 ---- myXScales[1] = myXScales[0]; + [self stopDrawing]; + myDataWanted[0] = myXScales[0] * mySampleRate + 1; myDataWanted[1] = myXScales[1] * mySampleRate + 1; *************** *** 111,114 **** --- 113,120 ---- myCollectedData[0] = malloc(myDataWanted[0] * sizeof(Sample)); myCollectedData[1] = malloc(myDataWanted[1] * sizeof(Sample)); + + myDataCollected[0] = 0; + myDataCollected[1] = 0; + [self startDrawing]; } *************** *** 122,127 **** } - [self stopDrawing]; - myYScales[0] = gVoltScales[[myYAScaleSlider intValue]-1] * pow(2.0, [myYAFineSlider doubleValue]); --- 128,131 ---- *************** *** 131,136 **** [self changedTriggerSettings: self]; } - - [self startDrawing]; } --- 135,138 ---- *************** *** 143,148 **** } - if(sender != self) { [self stopDrawing]; } - myYScales[1] = gVoltScales[[myYBScaleSlider intValue]-1] * pow(2.0, [myYBFineSlider doubleValue]); --- 145,148 ---- *************** *** 152,157 **** [self changedTriggerSettings: self]; } - - if(sender != self) { [self startDrawing]; } } --- 152,155 ---- *************** *** 238,242 **** // FIXME implement this function to set the controls appropriately from // default / saved values ! -(id) updateControls { return self; } - (id)updateDisplay: (int) inTrace --- 236,243 ---- // FIXME implement this function to set the controls appropriately from // default / saved values ! -(id) updateControls ! { ! return self; ! } - (id)updateDisplay: (int) inTrace |