Permalink
Browse files

o Don't call conversion buffer FileSize() etc. within status mutex

  lock; that way, we can enable the mutexes in conversion buffer.
  • Loading branch information...
1 parent c6994d4 commit 6d7bc9aeabbcafcf14684eb23ae92904f4080c3d @hzeller committed Oct 7, 2012
Showing with 16 additions and 13 deletions.
  1. +3 −6 conversion-buffer.cc
  2. +13 −7 folve-filesystem.cc
View
@@ -124,11 +124,8 @@ ssize_t ConversionBuffer::SndAppend(const void *data, size_t count) {
void ConversionBuffer::HeaderFinished() { header_end_ = FileSize(); }
-// Mmh, looks like we're calling ourself while in FillUntil() loop. Investigate.
-// Until then: don't lock mutex for simple access.
-
off_t ConversionBuffer::FileSize() const {
- //folve::MutexLock l(&mutex_);
+ folve::MutexLock l(&mutex_);
return FileSize_Locked();
}
@@ -137,12 +134,12 @@ off_t ConversionBuffer::FileSize_Locked() const {
}
off_t ConversionBuffer::MaxAccessed() const {
- //folve::MutexLock l(&mutex_);
+ folve::MutexLock l(&mutex_);
return max_accessed_;
}
bool ConversionBuffer::IsFileComplete() const {
- //folve::MutexLock l(&mutex_);
+ folve::MutexLock l(&mutex_);
return file_complete_;
}
View
@@ -211,19 +211,19 @@ class SndFileHandler :
}
virtual void GetHandlerStatus(HandlerStats *stats) {
- folve::MutexLock l(&stats_mutex_);
+ const off_t file_size = output_buffer_->FileSize();
+ const off_t max_access = output_buffer_->MaxAccessed();
if (processor_ != NULL) {
base_stats_.max_output_value = processor_->max_output_value();
}
*stats = base_stats_;
- const int frames_done = in_info_.frames - input_frames_left_;
+ const int frames_done = in_info_.frames - frames_left();
if (frames_done == 0 || in_info_.frames == 0) {
stats->buffer_progress = 0.0;
stats->access_progress = 0.0;
} else {
stats->buffer_progress = 1.0 * frames_done / in_info_.frames;
- stats->access_progress = stats->buffer_progress
- * output_buffer_->MaxAccessed() / output_buffer_->FileSize();
+ stats->access_progress = stats->buffer_progress * max_access / file_size;
}
if (base_stats_.max_output_value > 1.0) {
@@ -241,11 +241,12 @@ class SndFileHandler :
}
virtual int Stat(struct stat *st) {
- if (output_buffer_->FileSize() > start_estimating_size_) {
- const int frames_done = in_info_.frames - input_frames_left_;
+ const off_t current_file_size = output_buffer_->FileSize();
+ if (current_file_size > start_estimating_size_) {
+ const int frames_done = in_info_.frames - frames_left();
if (frames_done > 0) {
const float estimated_end = 1.0 * in_info_.frames / frames_done;
- off_t new_size = estimated_end * output_buffer_->FileSize();
+ off_t new_size = estimated_end * current_file_size;
// Report a bit bigger size which is less harmful than programs
// reading short.
new_size += 16384;
@@ -571,6 +572,11 @@ class SndFileHandler :
return memcmp(flac_magic, "fLaC", sizeof(flac_magic)) == 0;
}
+ int frames_left() {
+ folve::MutexLock l(&stats_mutex_);
+ return input_frames_left_;
+ }
+
FolveFilesystem *const fs_;
const int filedes_;
SNDFILE *const snd_in_;

0 comments on commit 6d7bc9a

Please sign in to comment.