|
MythTV master
|
This class supports the writing of recordings to disk. More...
#include <libmythbase/threadedfilewriter.h>
Classes | |
| class | TFWBuffer |
Public Member Functions | |
| ThreadedFileWriter (QString fname, int flags, mode_t mode) | |
| Creates a threaded file writer. More... | |
| ~ThreadedFileWriter () | |
| Commits all writes and closes the file. More... | |
| bool | Open (void) |
| Opens the file we will be writing to. More... | |
| bool | ReOpen (const QString &newFilename="") |
| Reopens the file we are writing to or opens a new file. More... | |
| long long | Seek (long long pos, int whence) |
| Seek to a position within stream; May be unsafe. More... | |
| int | Write (const void *data, uint count) |
| Writes data to the end of the write buffer. More... | |
| void | SetWriteBufferMinWriteSize (uint newMinSize=kMinWriteSize) |
| Sets the minumum number of bytes to write to disk in a single write. More... | |
| void | Sync (void) const |
| Flush data written to the file descriptor to disk. More... | |
| void | Flush (void) |
| Allow DiskLoop() to flush buffer completely ignoring low watermark. More... | |
| bool | SetBlocking (bool block=true) |
| Set write blocking mode While in blocking mode, ThreadedFileWriter::Write will wait for buffers to be freed as required, so there's never any data loss. More... | |
| bool | WritesFailing (void) const |
Protected Member Functions | |
| void | DiskLoop (void) |
| The thread run method that actually calls writes to disk. More... | |
| void | SyncLoop (void) |
| The thread run method that calls Sync(void). More... | |
| void | TrimEmptyBuffers (void) |
Private Attributes | |
| QString | m_filename |
| int | m_flags |
| mode_t | m_mode |
| int | m_fd {-1} |
| bool | m_flush {false} |
| bool | m_inDtor {false} |
| bool | m_ignoreWrites {false} |
| uint | m_tfwMinWriteSize {kMinWriteSize} |
| uint | m_totalBufferUse {0} |
| QMutex | m_bufLock |
| QList< TFWBuffer * > | m_writeBuffers |
| QList< TFWBuffer * > | m_emptyBuffers |
| TFWWriteThread * | m_writeThread {nullptr} |
| TFWSyncThread * | m_syncThread {nullptr} |
| QWaitCondition | m_bufferEmpty |
| QWaitCondition | m_bufferHasData |
| QWaitCondition | m_bufferSyncWait |
| QWaitCondition | m_bufferWasFreed |
| bool | m_warned {false} |
| bool | m_blocking {false} |
| bool | m_registered {false} |
Static Private Attributes | |
| static const uint | kMaxBufferSize = 8 * 1024 * 1024 |
| static const uint | kMinWriteSize = 64 * 1024 |
| Minimum to write to disk in a single write, when not flushing buffer. More... | |
| static const uint | kMaxBlockSize = 1 * 1024 * 1024 |
| Maximum block size to write at a time. More... | |
Friends | |
| class | TFWWriteThread |
| class | TFWSyncThread |
This class supports the writing of recordings to disk.
This class allows us manage the buffering when writing to disk. We write to the kernel image of the disk using one thread, and sync the kernel's image of the disk to hardware using another thread. The goal here so to block as little as possible when the classes using this class want to add data to the stream.
Definition at line 44 of file threadedfilewriter.h.
|
inline |
Creates a threaded file writer.
Definition at line 52 of file threadedfilewriter.h.
| ThreadedFileWriter::~ThreadedFileWriter | ( | ) |
Commits all writes and closes the file.
Definition at line 143 of file threadedfilewriter.cpp.
|
protected |
The thread run method that actually calls writes to disk.
Definition at line 415 of file threadedfilewriter.cpp.
Referenced by TFWWriteThread::run().
| void ThreadedFileWriter::Flush | ( | void | ) |
Allow DiskLoop() to flush buffer completely ignoring low watermark.
Definition at line 324 of file threadedfilewriter.cpp.
Referenced by RemoteFile::GetFileSize(), ReOpen(), MythMediaBuffer::WriterFlush(), MythMediaBuffer::~MythMediaBuffer(), and ~ThreadedFileWriter().
| bool ThreadedFileWriter::Open | ( | void | ) |
Opens the file we will be writing to.
Definition at line 96 of file threadedfilewriter.cpp.
Referenced by StreamHandler::AddNamedOutputFile(), MythFileBuffer::MythFileBuffer(), RemoteFile::OpenInternal(), and ReOpen().
| bool ThreadedFileWriter::ReOpen | ( | const QString & | newFilename = "" | ) |
Reopens the file we are writing to or opens a new file.
| newFilename | optional name of new file to open |
Definition at line 67 of file threadedfilewriter.cpp.
Referenced by MythFileBuffer::ReOpen().
| long long ThreadedFileWriter::Seek | ( | long long | pos, |
| int | whence | ||
| ) |
Seek to a position within stream; May be unsafe.
This method is unsafe if Start() has been called and the call us not preceeded by StopReads(). You probably want to follow Seek() with a StartReads() in this case.
This method assumes that we don't seek very often. It does not use a high performance approach... we just block until the write thread empties the buffer.
Definition at line 303 of file threadedfilewriter.cpp.
Referenced by RemoteFile::SeekInternal(), and MythMediaBuffer::WriterSeek().
| bool ThreadedFileWriter::SetBlocking | ( | bool | block = true | ) |
Set write blocking mode While in blocking mode, ThreadedFileWriter::Write will wait for buffers to be freed as required, so there's never any data loss.
| block | False if not blocking, true if blocking |
Definition at line 619 of file threadedfilewriter.cpp.
Referenced by RemoteFile::SetBlocking(), and MythMediaBuffer::WriterSetBlocking().
| void ThreadedFileWriter::SetWriteBufferMinWriteSize | ( | uint | newMinSize = kMinWriteSize | ) |
Sets the minumum number of bytes to write to disk in a single write.
This is ignored during a Flush(void)
Definition at line 380 of file threadedfilewriter.cpp.
| void ThreadedFileWriter::Sync | ( | void | ) | const |
Flush data written to the file descriptor to disk.
This prevents freezing up Linux disk access on a running CFQ, AS, or Deadline as the disk write schedulers. It does this via two mechanism. One is a data sync using the best mechanism available (fdatasync then fsync). The second is by telling the kernel we do not intend to use the data just written anytime soon so other processes time-slices will not be used to deal with our excess dirty pages.
Definition at line 361 of file threadedfilewriter.cpp.
Referenced by MythMediaBuffer::Sync(), and SyncLoop().
|
protected |
The thread run method that calls Sync(void).
Definition at line 391 of file threadedfilewriter.cpp.
Referenced by TFWSyncThread::run().
|
protected |
Definition at line 592 of file threadedfilewriter.cpp.
Referenced by DiskLoop().
| int ThreadedFileWriter::Write | ( | const void * | data, |
| uint | count | ||
| ) |
Writes data to the end of the write buffer.
| data | pointer to data to write to disk |
| count | size of data in bytes |
Definition at line 196 of file threadedfilewriter.cpp.
Referenced by MythMediaBuffer::Write(), RemoteFile::Write(), and StreamHandler::WriteMPTS().
|
inline |
Definition at line 67 of file threadedfilewriter.h.
|
friend |
Definition at line 47 of file threadedfilewriter.h.
Referenced by Open().
|
friend |
Definition at line 46 of file threadedfilewriter.h.
Referenced by Open().
|
staticprivate |
Maximum block size to write at a time.
Definition at line 114 of file threadedfilewriter.h.
Referenced by Write().
|
staticprivate |
Definition at line 110 of file threadedfilewriter.h.
Referenced by Write().
|
staticprivate |
Minimum to write to disk in a single write, when not flushing buffer.
Definition at line 112 of file threadedfilewriter.h.
Referenced by DiskLoop(), and Write().
|
private |
Definition at line 117 of file threadedfilewriter.h.
Referenced by SetBlocking(), and Write().
|
private |
Definition at line 104 of file threadedfilewriter.h.
Referenced by DiskLoop(), Flush(), and Seek().
|
private |
Definition at line 105 of file threadedfilewriter.h.
Referenced by DiskLoop(), Flush(), Seek(), SetWriteBufferMinWriteSize(), Write(), and ~ThreadedFileWriter().
|
private |
Definition at line 106 of file threadedfilewriter.h.
Referenced by SyncLoop(), and ~ThreadedFileWriter().
|
private |
Definition at line 107 of file threadedfilewriter.h.
Referenced by DiskLoop(), and Write().
|
mutableprivate |
Definition at line 95 of file threadedfilewriter.h.
Referenced by DiskLoop(), Flush(), ReOpen(), Seek(), SetWriteBufferMinWriteSize(), SyncLoop(), Write(), and ~ThreadedFileWriter().
|
private |
Definition at line 97 of file threadedfilewriter.h.
Referenced by DiskLoop(), TrimEmptyBuffers(), Write(), and ~ThreadedFileWriter().
|
private |
Definition at line 79 of file threadedfilewriter.h.
Referenced by DiskLoop(), Open(), ReOpen(), Seek(), Sync(), and ~ThreadedFileWriter().
|
private |
Definition at line 76 of file threadedfilewriter.h.
Referenced by DiskLoop(), Open(), ReOpen(), SyncLoop(), and ~ThreadedFileWriter().
|
private |
Definition at line 77 of file threadedfilewriter.h.
Referenced by Open().
|
private |
Definition at line 82 of file threadedfilewriter.h.
Referenced by DiskLoop(), Flush(), and Seek().
|
private |
Definition at line 84 of file threadedfilewriter.h.
Referenced by DiskLoop(), Open(), SyncLoop(), and Write().
|
private |
Definition at line 83 of file threadedfilewriter.h.
Referenced by DiskLoop(), SyncLoop(), and ~ThreadedFileWriter().
|
private |
Definition at line 78 of file threadedfilewriter.h.
Referenced by Open().
|
private |
Definition at line 118 of file threadedfilewriter.h.
Referenced by DiskLoop(), Open(), ReOpen(), SyncLoop(), and ~ThreadedFileWriter().
|
private |
Definition at line 101 of file threadedfilewriter.h.
Referenced by Open(), and ~ThreadedFileWriter().
|
private |
Definition at line 85 of file threadedfilewriter.h.
Referenced by SetWriteBufferMinWriteSize().
|
private |
Definition at line 86 of file threadedfilewriter.h.
Referenced by DiskLoop(), Flush(), Seek(), and Write().
|
private |
Definition at line 116 of file threadedfilewriter.h.
Referenced by Write().
|
private |
Definition at line 96 of file threadedfilewriter.h.
Referenced by DiskLoop(), Flush(), Seek(), Write(), and ~ThreadedFileWriter().
|
private |
Definition at line 100 of file threadedfilewriter.h.
Referenced by Open(), and ~ThreadedFileWriter().