1 // TortoiseSVN - a Windows shell extension for easy version control
3 // External Cache Copyright (C) 2005 - 2006 - Will Dean, Stefan Kueng
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "CacheInterface.h"
24 //////////////////////////////////////////////////////////////////////////
28 #pragma pack(push, r1, 16)
32 * Helper class to crawl folders in the background (in a separate thread)
33 * so that the main cache isn't blocked until all the status are fetched.
39 ~CFolderCrawler(void);
43 void AddDirectoryForUpdate(const CTGitPath
& path
);
44 void AddPathForUpdate(const CTGitPath
& path
);
46 bool SetHoldoff(DWORD milliseconds
= 100);
47 void BlockPath(const CTGitPath
& path
, DWORD ticks
= 0);
49 static unsigned int __stdcall
ThreadEntry(void* pContext
);
53 CComAutoCriticalSection m_critSec
;
55 std::deque
<CTGitPath
> m_foldersToUpdate
;
56 std::deque
<CTGitPath
> m_pathsToUpdate
;
57 HANDLE m_hTerminationEvent
;
60 // This will be *asynchronously* modified by CCrawlInhibitor.
61 // So, we have to mark it volatile, preparing compiler and
62 // optimizer for the "worst".
63 volatile LONG m_lCrawlInhibitSet
;
65 // While the shell is still asking for items, we don't
66 // want to start crawling. This timer is pushed-out for
67 // every shell request, and stops us crawling until
68 // a bit of quiet time has elapsed
69 long m_crawlHoldoffReleasesAt
;
70 bool m_bItemsAddedSinceLastCrawl
;
71 bool m_bPathsAddedSinceLastCrawl
;
73 CTGitPath m_blockedPath
;
74 DWORD m_blockReleasesAt
;
78 friend class CCrawlInhibitor
;
82 //////////////////////////////////////////////////////////////////////////
88 CCrawlInhibitor(); // Not defined
90 explicit CCrawlInhibitor(CFolderCrawler
* pCrawler
)
92 m_pCrawler
= pCrawler
;
94 // Count locks instead of a mere flag toggle (exchange)
95 // to allow for multiple, concurrent locks.
96 ::InterlockedIncrement(&m_pCrawler
->m_lCrawlInhibitSet
);
100 ::InterlockedDecrement(&m_pCrawler
->m_lCrawlInhibitSet
);
101 m_pCrawler
->SetHoldoff();
104 CFolderCrawler
* m_pCrawler
;
107 #pragma pack(pop, r1)