1
// TortoiseGit - a Windows shell extension for easy version control
3 // External Cache Copyright (C) 2005-2007, 2009-2011, 2014 TortoiseSVN
4 // Copyright (C) 2008-2012, 2023 - 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"
24 #include "SmartHandle.h"
25 #include "UniqueQueue.h"
27 //////////////////////////////////////////////////////////////////////////
31 #pragma pack(push, r1, 16)
35 * Helper class to crawl folders in the background (in a separate thread)
36 * so that the main cache isn't blocked until all the status are fetched.
46 void AddDirectoryForUpdate(const CTGitPath
& path
);
47 void AddPathForUpdate(const CTGitPath
& path
);
48 void ReleasePathForUpdate(const CTGitPath
& path
);
50 bool SetHoldoff(DWORD milliseconds
= 100);
51 void BlockPath(const CTGitPath
& path
, DWORD ticks
= 0);
53 static unsigned int __stdcall
ThreadEntry(void* pContext
);
57 CComAutoCriticalSection m_critSec
;
58 CAutoGeneralHandle m_hThread
;
59 UniqueQueue
<CTGitPath
> m_foldersToUpdate
;
60 UniqueQueue
<CTGitPath
> m_pathsToUpdate
;
61 UniqueQueue
<CTGitPath
> m_pathsToRelease
;
63 CAutoGeneralHandle m_hTerminationEvent
;
64 CAutoGeneralHandle m_hWakeEvent
;
66 // This will be *asynchronously* modified by CCrawlInhibitor.
67 // So, we have to mark it volatile, preparing compiler and
68 // optimizer for the "worst".
69 volatile LONG m_lCrawlInhibitSet
= 0;
71 // While the shell is still asking for items, we don't
72 // want to start crawling. This timer is pushed-out for
73 // every shell request, and stops us crawling until
74 // a bit of quiet time has elapsed
75 LONGLONG m_crawlHoldoffReleasesAt
;
76 bool m_bItemsAddedSinceLastCrawl
= false;
77 bool m_bPathsAddedSinceLastCrawl
= false;
79 CTGitPath m_blockedPath
;
80 ULONGLONG m_blockReleasesAt
= 0;
84 friend class CCrawlInhibitor
;
88 //////////////////////////////////////////////////////////////////////////
94 CCrawlInhibitor(); // Not defined
96 explicit CCrawlInhibitor(CFolderCrawler
* pCrawler
)
98 m_pCrawler
= pCrawler
;
100 // Count locks instead of a mere flag toggle (exchange)
101 // to allow for multiple, concurrent locks.
102 ::InterlockedIncrement(&m_pCrawler
->m_lCrawlInhibitSet
);
106 ::InterlockedDecrement(&m_pCrawler
->m_lCrawlInhibitSet
);
107 m_pCrawler
->SetHoldoff();
110 CFolderCrawler
* m_pCrawler
;
113 #pragma pack(pop, r1)