Skip to content

Commit

Permalink
Train - Limit ant+/btle thread exclusion to avoid deadlocks
Browse files Browse the repository at this point in the history
Mutual exclusion was held while the training file is imported after
workout stop, this was a mistake introduced in my previous commits
since it can lead to deadlocs. Sorry.
  • Loading branch information
amtriathlon committed Feb 12, 2022
1 parent f09e357 commit 7417e9c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/Train/TrainSidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1384,10 +1384,6 @@ void TrainSidebar::Pause() // pause capture to recalibrate

void TrainSidebar::Stop(int deviceStatus) // when stop button is pressed
{
// Mutual exclusion with ANT+/BTLE threads to close the rr/vo2 files
QMutexLocker rrlocker(&rrMutex);
QMutexLocker vo2locker(&vo2Mutex);

if ((status&RT_RUNNING) == 0) return;

// re-enable the screen saver on Windows
Expand Down Expand Up @@ -1434,6 +1430,13 @@ void TrainSidebar::Stop(int deviceStatus) // when stop button is pressed
// close and reset File
recordFile->close();

// Request mutual exclusion with ANT+/BTLE threads to change status and close rr/vo2 files
rrMutex.lock();
vo2Mutex.lock();

// cancel recording
status &= ~RT_RECORDING;

// close rrFile
if (rrFile) {
//fprintf(stderr, "Closing r-r file\n"); fflush(stderr);
Expand All @@ -1450,6 +1453,10 @@ void TrainSidebar::Stop(int deviceStatus) // when stop button is pressed
vo2File=NULL;
}

// Release mutual exclusion with ANT+/BTLE threads before to open import dialog to avoid deadlocks
rrMutex.unlock();
vo2Mutex.unlock();

if(deviceStatus == DEVICE_ERROR)
{
recordFile->remove();
Expand All @@ -1465,9 +1472,6 @@ void TrainSidebar::Stop(int deviceStatus) // when stop button is pressed
RideImportWizard *dialog = new RideImportWizard (list, context);
dialog->process(); // do it!
}

// cancel recording
status &= ~RT_RECORDING;
}

load_timer->stop();
Expand Down

2 comments on commit 7417e9c

@acodring
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I got caught by this last night and it seems like I have a set of activity files stuck in limbo. I can see the files in 'records' and 'cache' but the activity does not show in my Activities list and does not upload to Strava.

Is there something simple I can do to unstick these activity files?

If that won't be possible, do I need to delete files to clear these out? Each time I try to 'Share | Upload | Strava' now it looks like it's trying to upload a file (2022_02_22_21_00_00.tcx.gz), so I'm not sure what will happen when I record my next activity.

In case it's not obvious I'm not a dev. Thank you for putting in the effort on this software. It's pretty awesome.

@amtriathlon
Copy link
Member Author

@amtriathlon amtriathlon commented on 7417e9c Feb 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read de FAQs, there’s an entry explaining how to import records after abnormal termination of Train sessions, and use the users forum if you have questions.
PS: latest snapshot builds in main site include this fix.

Please sign in to comment.