diff --git a/io/io/inc/TFilePrefetch.h b/io/io/inc/TFilePrefetch.h index a70aaeef4ca22761deecd443f46954e179ae2b83..1d0f0d00dfc0cd37c712521157dce84122cfb4a5 100644 --- a/io/io/inc/TFilePrefetch.h +++ b/io/io/inc/TFilePrefetch.h @@ -83,7 +83,7 @@ private: TString fPathCache; // path to the cache directory TStopwatch fWaitTime; // time wating to prefetch a buffer (in usec) - static void ThreadProc(void*); + static TThread::VoidRtnFunc_t ThreadProc(void*); //create a joinable worker thread public: TFilePrefetch(TFile*); diff --git a/io/io/src/TFilePrefetch.cxx b/io/io/src/TFilePrefetch.cxx index 9f8ddc8bf75fdc59d38528fbf01e03164a4c2bf1..a75d9b84fd8bc9ce4858b23def467b36a2502baa 100644 --- a/io/io/src/TFilePrefetch.cxx +++ b/io/io/src/TFilePrefetch.cxx @@ -56,6 +56,8 @@ TFilePrefetch::~TFilePrefetch() //killing consumer thread fSem->Post(); fNewBlockAdded->Signal(); + fConsumer->Join(); + fConsumer->Delete(); delete fPendingBlocks; delete fReadBlocks; @@ -299,15 +301,14 @@ Int_t TFilePrefetch::ThreadStart() { // Used to start the consumer thread. - fConsumer= new TThread("consumerThread", - (void(*) (void *))ThreadProc, + fConsumer= new TThread((TThread::VoidRtnFunc_t) ThreadProc, (void*) this); fConsumer->Run(); return 1; } //____________________________________________________________________________________________ -void TFilePrefetch::ThreadProc(void* arg) +TThread::VoidRtnFunc_t TFilePrefetch::ThreadProc(void* arg) { // Execution loop of the consumer thread. @@ -315,8 +316,11 @@ void TFilePrefetch::ThreadProc(void* arg) while(tmp->fSem->TryWait() !=0){ tmp->ReadListOfBlocks(); + if (tmp->fSem->TryWait() == 0) break; tmp->fNewBlockAdded->Wait(); } + + return (TThread::VoidRtnFunc_t) 1; } //########################################### CACHING PART ############################################################### diff --git a/tree/tree/src/TTreeCache.cxx b/tree/tree/src/TTreeCache.cxx index ee92ad13c8330a9a0d443acdb06a0544cc71f44d..6142919390cce01bc45222fc851f4fe6b3ad25d6 100644 --- a/tree/tree/src/TTreeCache.cxx +++ b/tree/tree/src/TTreeCache.cxx @@ -471,7 +471,7 @@ Bool_t TTreeCache::FillBuffer() } if (fReverseRead){ //reverse reading with prefetching - if (fEntryCurrent >0 && entry >= fEntryCurrent && entry < fEntryNext){ + if (fEntryCurrent >0 && entry < fEntryNext){ //we can prefetch the next buffer entry = fEntryCurrent - tree->GetAutoFlush() * fFillTimes; if (entry < 0) @@ -779,21 +779,16 @@ Int_t TTreeCache::ReadBufferPrefetch(char *buf, Long64_t pos, Int_t len){ return 1; } - //not found in cache. Do we need to fill the cache? - Bool_t bufferFilled = FillBuffer(); - if (bufferFilled) { - Int_t res = TFileCacheRead::ReadBuffer(buf,pos,len); - - if (res == 1) - fNReadOk++; - else if (res == 0) + //keep on prefetching until request is satisfied + while (1){ + if(TFileCacheRead::ReadBuffer(buf, pos, len)) + break; + FillBuffer(); fNReadMiss++; - - return res; } - fNReadMiss++; - return 0; + fNReadOk++; + return 1; } //_____________________________________________________________________________