Permalink
Browse files

o Reduce lock contention.

  • Loading branch information...
1 parent e3e1a0b commit 236972d825907c838a6b84207b1559e3bc295902 @hzeller committed Oct 14, 2012
Showing with 11 additions and 20 deletions.
  1. +3 −8 buffer-thread.cc
  2. +0 −2 buffer-thread.h
  3. +2 −1 conversion-buffer.cc
  4. +2 −1 conversion-buffer.h
  5. +4 −8 convolve-file-handler.cc
View
@@ -69,10 +69,6 @@ void BufferThread::Forget(ConversionBuffer *buffer) {
}
}
-bool BufferThread::IsWorkComplete(const WorkItem &work) const {
- return work.buffer->IsFileComplete() || work.buffer->FileSize() >= work.goal;
-}
-
void BufferThread::Run() {
const int kBufferChunk = (8 << 10);
for (;;) {
@@ -89,11 +85,10 @@ void BufferThread::Run() {
// We only do one chunk at the time so that the main thread has a chance to
// get into there and _we_ can round-robin through all work scheduled.
- if (!IsWorkComplete(work)) {
- work.buffer->FillUntil(work.buffer->FileSize() + kBufferChunk);
- }
+ const bool work_complete
+ = (work.buffer->FillUntil(work.buffer->FileSize() + kBufferChunk)
+ || work.buffer->FileSize() >= work.goal);
- const bool work_complete = IsWorkComplete(work);
{
folve::MutexLock l(&mutex_);
assert(queue_.front().buffer == current_work_buffer_);
View
@@ -43,8 +43,6 @@ class BufferThread : public folve::Thread {
};
typedef std::list<WorkItem> WorkQueue;
- bool IsWorkComplete(const WorkItem &work) const;
-
const int buffer_ahead_size_;
folve::Mutex mutex_;
View
@@ -148,7 +148,7 @@ bool ConversionBuffer::IsFileComplete() const {
return file_complete_;
}
-void ConversionBuffer::FillUntil(off_t requested_min_written) {
+bool ConversionBuffer::FillUntil(off_t requested_min_written) {
// As soon as someone tries to read beyond of what we already have, we call
// the callback that fills more of it.
// We are shared between potentially several open files. Serialize threads.
@@ -159,6 +159,7 @@ void ConversionBuffer::FillUntil(off_t requested_min_written) {
break;
}
}
+ return file_complete_;
}
ssize_t ConversionBuffer::Read(char *buf, size_t size, off_t offset) {
View
@@ -72,7 +72,8 @@ class ConversionBuffer {
void WriteCharAt(unsigned char c, off_t offset);
// Fill read file until we have the required bytes available.
- void FillUntil(off_t requested_min_written);
+ // Return 'true' if file is complete
+ bool FillUntil(off_t requested_min_written);
// Enable writing through the SNDFILE.
// If set to 'false', writes via the SNDFILE are ignored.
View
@@ -128,9 +128,9 @@ int ConvolveFileHandler::Read(char *buf, size_t size, off_t offset) {
// NotifyPassedProcessorUnreferenced()) - so that important use-case is
// covered.
const off_t well_beyond_header = output_buffer_->HeaderSize() + (64 << 10);
- const bool should_request_prebuffer = !output_buffer_->IsFileComplete()
- && read_horizon > well_beyond_header
- && read_horizon + fs_->pre_buffer_size() > current_filesize;
+ const bool should_request_prebuffer = read_horizon > well_beyond_header
+ && read_horizon + fs_->pre_buffer_size() > current_filesize
+ && !output_buffer_->IsFileComplete();
if (should_request_prebuffer) {
fs_->RequestPrebuffer(output_buffer_);
}
@@ -169,11 +169,7 @@ void ConvolveFileHandler::GetHandlerStatus(HandlerStats *stats) {
int ConvolveFileHandler::Stat(struct stat *st) {
const off_t current_file_size = output_buffer_->FileSize();
- if (output_buffer_->IsFileComplete()) {
- // Once we're complete, we know exactly the final size.
- file_stat_.st_size = current_file_size;
- }
- else if (current_file_size > start_estimating_size_) {
+ 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;

0 comments on commit 236972d

Please sign in to comment.