Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve failure handling when multithreading #681

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/libFLAC/stream_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -3413,9 +3413,10 @@ FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_block
#ifdef HAVE_PTHREAD
uint32_t i;
#endif
FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);

if(encoder->protected_->num_threads < 2 || is_last_block) {

FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);

/*
* Accumulate raw signal to the MD5 signature
*/
Expand Down Expand Up @@ -3535,10 +3536,13 @@ FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_last_block
}
}
/* Task is finished, write bitbuffer */
if(!encoder->private_->threadtask[encoder->private_->next_thread]->returnvalue)
if(!encoder->private_->threadtask[encoder->private_->next_thread]->returnvalue) {
pthread_mutex_unlock(&encoder->private_->threadtask[encoder->private_->next_thread]->mutex_this_task);
return false;
}
if(!write_bitbuffer_(encoder, encoder->private_->threadtask[encoder->private_->next_thread], encoder->protected_->blocksize, is_last_block)) {
/* the above function sets the state for us in case of an error */
pthread_mutex_unlock(&encoder->private_->threadtask[encoder->private_->next_thread]->mutex_this_task);
return false;
}
pthread_mutex_unlock(&encoder->private_->threadtask[encoder->private_->next_thread]->mutex_this_task);
Expand Down Expand Up @@ -3696,7 +3700,7 @@ FLAC__bool process_frame_thread_inner_(FLAC__StreamEncoder * encoder, FLAC__Stre
/*
* CRC-16 the whole thing
*/
FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(task->frame));
FLAC__ASSERT(!ok || FLAC__bitwriter_is_byte_aligned(task->frame));
if(
ok &&
(
Expand Down
Loading