|
MythTV
0.26-pre
|
This class supports the writing of recordings to disk. More...
#include <ThreadedFileWriter.h>
Classes | |
| class | TFWBuffer |
Public Member Functions | |
| ThreadedFileWriter (const QString &fname, int flags, mode_t mode) | |
| Creates a threaded file writer. | |
| ~ThreadedFileWriter () | |
| Commits all writes and closes the file. | |
| bool | Open (void) |
| Opens the file we will be writing to. | |
| bool | ReOpen (QString newFilename="") |
| Reopens the file we are writing to or opens a new file. | |
| long long | Seek (long long pos, int whence) |
| Seek to a position within stream; May be unsafe. | |
| uint | Write (const void *data, uint count) |
| Writes data to the end of the write buffer. | |
| void | SetWriteBufferMinWriteSize (uint newMinSize=kMinWriteSize) |
| Sets the minumum number of bytes to write to disk in a single write. | |
| void | Sync (void) |
| Flush data written to the file descriptor to disk. | |
| void | Flush (void) |
| Allow DiskLoop() to flush buffer completely ignoring low watermark. | |
Protected Member Functions | |
| void | DiskLoop (void) |
| The thread run method that actually calls writes to disk. | |
| void | SyncLoop (void) |
| The thread run method that calls Sync(void). | |
| void | TrimEmptyBuffers (void) |
Private Attributes | |
| QString | filename |
| int | flags |
| mode_t | mode |
| int | fd |
| bool | flush |
| bool | in_dtor |
| bool | ignore_writes |
| uint | tfw_min_write_size |
| uint | totalBufferUse |
| QMutex | buflock |
| QList< TFWBuffer * > | writeBuffers |
| QList< TFWBuffer * > | emptyBuffers |
| TFWWriteThread * | writeThread |
| TFWSyncThread * | syncThread |
| QWaitCondition | bufferEmpty |
| QWaitCondition | bufferHasData |
| QWaitCondition | bufferSyncWait |
Static Private Attributes | |
| static const uint | kMaxBufferSize = 128 * 1024 * 1024 |
| static const uint | kMinWriteSize = 64 * 1024 |
| Minimum to write to disk in a single write, when not flushing buffer. | |
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 40 of file ThreadedFileWriter.h.
| ThreadedFileWriter::ThreadedFileWriter | ( | const QString & | fname, |
| int | flags, | ||
| mode_t | mode | ||
| ) |
Creates a threaded file writer.
Definition at line 59 of file ThreadedFileWriter.cpp.
Commits all writes and closes the file.
Definition at line 148 of file ThreadedFileWriter.cpp.
Opens the file we will be writing to.
Definition at line 104 of file ThreadedFileWriter.cpp.
Referenced by FileRingBuffer::FileRingBuffer(), named_output_file_common(), and ReOpen().
| bool ThreadedFileWriter::ReOpen | ( | 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 80 of file ThreadedFileWriter.cpp.
Referenced by FileRingBuffer::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 269 of file ThreadedFileWriter.cpp.
Referenced by RingBuffer::WriterSeek().
| uint 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 198 of file ThreadedFileWriter.cpp.
Referenced by ASIStreamHandler::run(), and RingBuffer::Write().
| 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 346 of file ThreadedFileWriter.cpp.
Referenced by RingBuffer::SetWriteBufferMinWriteSize().
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 327 of file ThreadedFileWriter.cpp.
Referenced by RingBuffer::Sync(), SyncLoop(), and RingBuffer::WriterFlush().
Allow DiskLoop() to flush buffer completely ignoring low watermark.
Definition at line 290 of file ThreadedFileWriter.cpp.
Referenced by ReOpen(), RingBuffer::WriterFlush(), RingBuffer::~RingBuffer(), and ~ThreadedFileWriter().
| void ThreadedFileWriter::DiskLoop | ( | void | ) | [protected] |
The thread run method that actually calls writes to disk.
Definition at line 374 of file ThreadedFileWriter.cpp.
Referenced by TFWWriteThread::run().
| void ThreadedFileWriter::SyncLoop | ( | void | ) | [protected] |
The thread run method that calls Sync(void).
Definition at line 357 of file ThreadedFileWriter.cpp.
Referenced by TFWSyncThread::run().
| void ThreadedFileWriter::TrimEmptyBuffers | ( | void | ) | [protected] |
Definition at line 535 of file ThreadedFileWriter.cpp.
Referenced by DiskLoop().
friend class TFWWriteThread [friend] |
Definition at line 42 of file ThreadedFileWriter.h.
Referenced by Open().
friend class TFWSyncThread [friend] |
Definition at line 43 of file ThreadedFileWriter.h.
Referenced by Open().
QString ThreadedFileWriter::filename [private] |
Definition at line 66 of file ThreadedFileWriter.h.
Referenced by hardwareprofile.os_detect.OSWithFile::__get__(), DiskLoop(), hardwareprofile.os_detect.OSWithFile::do_test(), Open(), ReOpen(), and ThreadedFileWriter().
int ThreadedFileWriter::flags [private] |
Definition at line 67 of file ThreadedFileWriter.h.
Referenced by Open().
mode_t ThreadedFileWriter::mode [private] |
Definition at line 68 of file ThreadedFileWriter.h.
Referenced by Open().
int ThreadedFileWriter::fd [private] |
Definition at line 69 of file ThreadedFileWriter.h.
Referenced by DiskLoop(), Open(), ReOpen(), Seek(), Sync(), and ~ThreadedFileWriter().
bool ThreadedFileWriter::flush [private] |
Definition at line 72 of file ThreadedFileWriter.h.
Referenced by DiskLoop(), Flush(), and Seek().
bool ThreadedFileWriter::in_dtor [private] |
Definition at line 73 of file ThreadedFileWriter.h.
Referenced by DiskLoop(), SyncLoop(), and ~ThreadedFileWriter().
bool ThreadedFileWriter::ignore_writes [private] |
Definition at line 74 of file ThreadedFileWriter.h.
Referenced by DiskLoop(), Open(), and Write().
uint ThreadedFileWriter::tfw_min_write_size [private] |
Definition at line 75 of file ThreadedFileWriter.h.
Referenced by SetWriteBufferMinWriteSize().
uint ThreadedFileWriter::totalBufferUse [private] |
Definition at line 76 of file ThreadedFileWriter.h.
Referenced by DiskLoop(), Flush(), Seek(), and Write().
QMutex ThreadedFileWriter::buflock [mutable, private] |
Definition at line 85 of file ThreadedFileWriter.h.
Referenced by DiskLoop(), Flush(), ReOpen(), Seek(), SetWriteBufferMinWriteSize(), SyncLoop(), Write(), and ~ThreadedFileWriter().
QList<TFWBuffer*> ThreadedFileWriter::writeBuffers [private] |
Definition at line 86 of file ThreadedFileWriter.h.
Referenced by DiskLoop(), Flush(), Seek(), Write(), and ~ThreadedFileWriter().
QList<TFWBuffer*> ThreadedFileWriter::emptyBuffers [private] |
Definition at line 87 of file ThreadedFileWriter.h.
Referenced by DiskLoop(), TrimEmptyBuffers(), Write(), and ~ThreadedFileWriter().
TFWWriteThread* ThreadedFileWriter::writeThread [private] |
Definition at line 90 of file ThreadedFileWriter.h.
Referenced by Open(), and ~ThreadedFileWriter().
TFWSyncThread* ThreadedFileWriter::syncThread [private] |
Definition at line 91 of file ThreadedFileWriter.h.
Referenced by Open(), and ~ThreadedFileWriter().
QWaitCondition ThreadedFileWriter::bufferEmpty [private] |
Definition at line 94 of file ThreadedFileWriter.h.
Referenced by DiskLoop(), Flush(), and Seek().
QWaitCondition ThreadedFileWriter::bufferHasData [private] |
Definition at line 95 of file ThreadedFileWriter.h.
Referenced by DiskLoop(), Flush(), Seek(), SetWriteBufferMinWriteSize(), Write(), and ~ThreadedFileWriter().
QWaitCondition ThreadedFileWriter::bufferSyncWait [private] |
Definition at line 96 of file ThreadedFileWriter.h.
Referenced by SyncLoop(), and ~ThreadedFileWriter().
const uint ThreadedFileWriter::kMaxBufferSize = 128 * 1024 * 1024 [static, private] |
Definition at line 99 of file ThreadedFileWriter.h.
Referenced by Write().
const uint ThreadedFileWriter::kMinWriteSize = 64 * 1024 [static, private] |
Minimum to write to disk in a single write, when not flushing buffer.
Definition at line 101 of file ThreadedFileWriter.h.
Referenced by DiskLoop(), and Write().
1.7.6.1