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