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