Ticket #714: diskloop-rv.patch

File diskloop-rv.patch, 3.8 KB (added by danielk, 15 years ago)

backs out diskloop changes

  • libs/libmythtv/ThreadedFileWriter.cpp

     
    2323const uint ThreadedFileWriter::TFW_DEF_BUF_SIZE   = 2*1024*1024;
    2424const uint ThreadedFileWriter::TFW_MAX_WRITE_SIZE = TFW_DEF_BUF_SIZE / 4;
    2525const uint ThreadedFileWriter::TFW_MIN_WRITE_SIZE = TFW_DEF_BUF_SIZE / 8;
    26 const uint ThreadedFileWriter::TFW_BLK_WRITE_SIZE = 16*1024;
    2726
    2827/** \class ThreadedFileWriter
    2928 *  \brief This class supports the writing of recordings to disk.
     
    115114    mode(pmode),                         fd(-1),
    116115    // state
    117116    no_writes(false),                    flush(false),
    118     write_is_blocked(false),             in_dtor(false),
     117    in_dtor(false),
    119118    tfw_min_write_size(0),
    120119    // buffer position state
    121120    rpos(0),                             wpos(0),
     
    202201                    QString("cnt(%1) free(%2)").arg(count).arg(BufFree()));
    203202            first = false;
    204203        }
    205         write_is_blocked = true;
    206         bufferHasData.wakeAll(); // make sure DiskLoop is run soon...
     204
    207205        bufferWroteData.wait(100);
    208206    }
    209     write_is_blocked = false;
    210207    if (!first)
    211208        VERBOSE(VB_IMPORTANT, LOC_ERR + "Write() -- IOBOUND end");
    212209
     
    311308    buflock.unlock();
    312309}
    313310
    314 /** \fn ThreadedFileWriter::SetWriteBufferSize(uint)
     311/** \fn ThreadedFileWriter::SetWriteBufferMinWriteSize(uint)
    315312 *  \brief Sets the minumum number of bytes to write to disk in a single write.
    316313 *         This is ignored during a Flush(void)
    317314 */
     
    340337 */
    341338void ThreadedFileWriter::DiskLoop(void)
    342339{
    343     uint size = 0;
     340    uint size = 0, written = 0;
    344341
    345342    while (!in_dtor || BufUsed() > 0)
    346343    {
    347344        size = BufUsed();
    348345
    349         if (!size)
    350         {
     346        if (size == 0)
    351347            bufferEmpty.wakeAll();
    352             bufferHasData.wait(100);
    353             continue;
    354         }
    355         else if ((size < tfw_min_write_size) &&
    356                  (!in_dtor && !flush && !write_is_blocked))
     348
     349        if (!size || (!in_dtor && !flush &&
     350            ((size < tfw_min_write_size) &&
     351             (written >= tfw_min_write_size))))
    357352        {
    358             // we don't have enough data to bother writing to disk
    359353            bufferHasData.wait(100);
    360354            continue;
    361355        }
     
    363357        /* cap the max. write size. Prevents the situation where 90% of the
    364358           buffer is valid, and we try to write all of it at once which
    365359           takes a long time. During this time, the other thread fills up
    366            the 10% that was free...
    367            Then make write size even smaller if we are aleady blocked.
    368         */
     360           the 10% that was free... */
    369361        size = (size > TFW_MAX_WRITE_SIZE) ? TFW_MAX_WRITE_SIZE : size;
    370         size = (write_is_blocked)          ? TFW_BLK_WRITE_SIZE : size;
    371362
    372363        if ((rpos + size) > tfw_buf_size)
    373364        {
     
    382373            size = safe_write(fd, buf+rpos, size);
    383374        }
    384375
     376        if (written < tfw_min_write_size)
     377        {
     378            written += size;
     379        }
     380
    385381        buflock.lock();
    386382        rpos = (rpos + size) % tfw_buf_size;
    387383        buflock.unlock();
  • libs/libmythtv/ThreadedFileWriter.h

     
    7575    static const uint TFW_MAX_WRITE_SIZE;
    7676    /// Minimum to write to disk in a single write, when not flushing buffer.
    7777    static const uint TFW_MIN_WRITE_SIZE;
    78     /// Maximum to write to disk in s single write,
    79     /// if another thread is already waiting on disk thread.
    80     static const uint TFW_BLK_WRITE_SIZE;
    8178};
    8279
    8380#endif