{
boost::mutex::scoped_lock lock (_mutex);
+ while (_queued_full_in_memory > _maximum_frames_in_memory) {
+ _full_condition.wait (lock);
+ }
+
QueueItem qi;
qi.type = QueueItem::FULL;
qi.encoded = encoded;
++_queued_full_in_memory;
}
- _condition.notify_all ();
+ _empty_condition.notify_all ();
}
void
{
boost::mutex::scoped_lock lock (_mutex);
+ while (_queued_full_in_memory > _maximum_frames_in_memory) {
+ _full_condition.wait (lock);
+ }
+
FILE* ifi = fopen_boost (_film->info_path (frame, eyes), "r");
libdcp::FrameInfo info (ifi);
fclose (ifi);
_queue.push_back (qi);
}
- _condition.notify_all ();
+ _empty_condition.notify_all ();
}
/** This method is not thread safe */
}
TIMING (N_("writer sleeps with a queue of %1"), _queue.size());
- _condition.wait (lock);
+ _empty_condition.wait (lock);
TIMING (N_("writer wakes with a queue of %1"), _queue.size());
}
boost::mutex::scoped_lock lock (_mutex);
_finish = true;
- _condition.notify_all ();
+ _empty_condition.notify_all ();
+ _full_condition.notify_all ();
lock.unlock ();
_thread->join ();
meta.set_issue_date_now ();
dcp.write_xml (_film->interop (), meta, _film->is_signed() ? make_signer () : shared_ptr<const libdcp::Signer> ());
- _film->log()->log (String::compose (N_("Wrote %1 FULL, %2 FAKE, %3 REPEAT; %4 pushed to disk"), _full_written, _fake_written, _repeat_written, _pushed_to_disk));
+ _film->log()->log (
+ String::compose (N_("Wrote %1 FULL, %2 FAKE, %3 REPEAT; %4 pushed to disk"), _full_written, _fake_written, _repeat_written, _pushed_to_disk)
+ );
}
/** Tell the writer that frame `f' should be a repeat of the frame before it */
{
boost::mutex::scoped_lock lock (_mutex);
+ while (_queued_full_in_memory > _maximum_frames_in_memory) {
+ _full_condition.wait (lock);
+ }
+
QueueItem qi;
qi.type = QueueItem::REPEAT;
qi.frame = f;
_queue.push_back (qi);
}
- _condition.notify_all ();
+ _empty_condition.notify_all ();
}
bool
int _queued_full_in_memory;
/** mutex for thread state */
mutable boost::mutex _mutex;
- /** condition to manage thread wakeups */
- boost::condition _condition;
+ /** condition to manage thread wakeups when we have nothing to do */
+ boost::condition _empty_condition;
+ /** condition to manage thread wakeups when we have too much to do */
+ boost::condition _full_condition;
/** the data of the last written frame, or 0 if there isn't one */
boost::shared_ptr<const EncodedData> _last_written[EYES_COUNT];
/** the index of the last written frame */