/////////////////////////////////////////////////////////////////////
| 422 | ////////////////////////////////////////////////////////////////////////// |
| 423 | // |
| 424 | unsigned CRefStreamEngine::StartIOJobs() |
| 425 | { |
| 426 | unsigned numMovedJobs = 0; |
| 427 | AUTO_LOCK(m_csIOJobs); |
| 428 | { |
| 429 | AUTO_LOCK(m_csIOPending); |
| 430 | |
| 431 | CRefReadStreamProxy* pEndJob = NULL; // the job that will mark the end of loop |
| 432 | // TODO: implement limitation on the number of simultaneous read requests |
| 433 | while(!m_queIOJobs.empty() |
| 434 | && m_setIOPending.size() < m_nMaxReadDepth |
| 435 | && !IsSuspended()) |
| 436 | { |
| 437 | CRefReadStreamProxy_AutoPtr pProxy = m_queIOJobs.front(); |
| 438 | |
| 439 | m_queIOJobs.pop_front(); |
| 440 | m_setIOPending.insert (pProxy); |
| 441 | |
| 442 | // temporary unlock both queue and set and start the reading |
| 443 | bool bReadStarted; |
| 444 | { |
| 445 | AUTO_UNLOCK(m_csIOPending); |
| 446 | { |
| 447 | AUTO_UNLOCK(m_csIOJobs); |
| 448 | // try to start reading |
| 449 | bReadStarted = pProxy->StartRead(); |
| 450 | } |
| 451 | } |
| 452 | |
| 453 | if (bReadStarted) |
| 454 | { |
| 455 | // in case of no error - this should be in most cases: |
| 456 | // we started the operation successfully |
| 457 | // perhaps now it's even already read and moved from Pending to Executed queue |
| 458 | |
| 459 | // in case of unrecoverable error: |
| 460 | // we didn't start reading and can't do so. It's already moved into Executed queue as errorneous |
| 461 | ++numMovedJobs; |
| 462 | |
| 463 | pEndJob = NULL; // start the whole loop all over again. |
| 464 | } |
| 465 | else |
| 466 | { |
| 467 | // recoverable error - we'll try again next time |
| 468 | m_queIOJobs.push_back(pProxy); |
| 469 | m_setIOPending.erase (pProxy); |
| 470 | |
| 471 | if (pEndJob) |
| 472 | { |
| 473 | if (pEndJob == pProxy) |
| 474 | break; // we are looping - we can't start this job for the second time in a row now |
| 475 | } |
| 476 | else |
| 477 | { |
| 478 | pEndJob = pProxy; // mark this job as the end of loop; we'll erase the marker if the job is started |
| 479 | } |
| 480 | } |
| 481 | } |