Ticket #714: diskloop-rv.patch
File diskloop-rv.patch, 3.8 KB (added by , 15 years ago) |
---|
-
libs/libmythtv/ThreadedFileWriter.cpp
23 23 const uint ThreadedFileWriter::TFW_DEF_BUF_SIZE = 2*1024*1024; 24 24 const uint ThreadedFileWriter::TFW_MAX_WRITE_SIZE = TFW_DEF_BUF_SIZE / 4; 25 25 const uint ThreadedFileWriter::TFW_MIN_WRITE_SIZE = TFW_DEF_BUF_SIZE / 8; 26 const uint ThreadedFileWriter::TFW_BLK_WRITE_SIZE = 16*1024;27 26 28 27 /** \class ThreadedFileWriter 29 28 * \brief This class supports the writing of recordings to disk. … … 115 114 mode(pmode), fd(-1), 116 115 // state 117 116 no_writes(false), flush(false), 118 write_is_blocked(false),in_dtor(false),117 in_dtor(false), 119 118 tfw_min_write_size(0), 120 119 // buffer position state 121 120 rpos(0), wpos(0), … … 202 201 QString("cnt(%1) free(%2)").arg(count).arg(BufFree())); 203 202 first = false; 204 203 } 205 write_is_blocked = true; 206 bufferHasData.wakeAll(); // make sure DiskLoop is run soon... 204 207 205 bufferWroteData.wait(100); 208 206 } 209 write_is_blocked = false;210 207 if (!first) 211 208 VERBOSE(VB_IMPORTANT, LOC_ERR + "Write() -- IOBOUND end"); 212 209 … … 311 308 buflock.unlock(); 312 309 } 313 310 314 /** \fn ThreadedFileWriter::SetWriteBuffer Size(uint)311 /** \fn ThreadedFileWriter::SetWriteBufferMinWriteSize(uint) 315 312 * \brief Sets the minumum number of bytes to write to disk in a single write. 316 313 * This is ignored during a Flush(void) 317 314 */ … … 340 337 */ 341 338 void ThreadedFileWriter::DiskLoop(void) 342 339 { 343 uint size = 0 ;340 uint size = 0, written = 0; 344 341 345 342 while (!in_dtor || BufUsed() > 0) 346 343 { 347 344 size = BufUsed(); 348 345 349 if (!size) 350 { 346 if (size == 0) 351 347 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)))) 357 352 { 358 // we don't have enough data to bother writing to disk359 353 bufferHasData.wait(100); 360 354 continue; 361 355 } … … 363 357 /* cap the max. write size. Prevents the situation where 90% of the 364 358 buffer is valid, and we try to write all of it at once which 365 359 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... */ 369 361 size = (size > TFW_MAX_WRITE_SIZE) ? TFW_MAX_WRITE_SIZE : size; 370 size = (write_is_blocked) ? TFW_BLK_WRITE_SIZE : size;371 362 372 363 if ((rpos + size) > tfw_buf_size) 373 364 { … … 382 373 size = safe_write(fd, buf+rpos, size); 383 374 } 384 375 376 if (written < tfw_min_write_size) 377 { 378 written += size; 379 } 380 385 381 buflock.lock(); 386 382 rpos = (rpos + size) % tfw_buf_size; 387 383 buflock.unlock(); -
libs/libmythtv/ThreadedFileWriter.h
75 75 static const uint TFW_MAX_WRITE_SIZE; 76 76 /// Minimum to write to disk in a single write, when not flushing buffer. 77 77 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;81 78 }; 82 79 83 80 #endif