Fix TGitCache RunTime 4->1 check fail problem. Add submodule status at shell extension
[TortoiseGit.git] / src / TGitCache / FolderCrawler.h
blob9e89e5158af5f75e2e13e0e67271d7492a1b4d94
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.
19 #pragma once
21 #include "TGitPath.h"
22 #include "CacheInterface.h"
23 #include <set>
24 //////////////////////////////////////////////////////////////////////////
28 #pragma pack(push, r1, 16)
30 /**
31 * \ingroup TSVNCache
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.
35 class CFolderCrawler
37 public:
38 CFolderCrawler(void);
39 ~CFolderCrawler(void);
41 public:
42 void Initialise();
43 void AddDirectoryForUpdate(const CTGitPath& path);
44 void AddPathForUpdate(const CTGitPath& path);
45 void Stop();
46 bool SetHoldoff(DWORD milliseconds = 100);
47 void BlockPath(const CTGitPath& path, DWORD ticks = 0);
48 private:
49 static unsigned int __stdcall ThreadEntry(void* pContext);
50 void WorkerThread();
52 private:
53 CComAutoCriticalSection m_critSec;
54 HANDLE m_hThread;
55 std::deque<CTGitPath> m_foldersToUpdate;
56 std::deque<CTGitPath> m_pathsToUpdate;
57 HANDLE m_hTerminationEvent;
58 HANDLE m_hWakeEvent;
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;
75 bool m_bRun;
78 friend class CCrawlInhibitor;
82 //////////////////////////////////////////////////////////////////////////
85 class CCrawlInhibitor
87 private:
88 CCrawlInhibitor(); // Not defined
89 public:
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);
98 ~CCrawlInhibitor()
100 ::InterlockedDecrement(&m_pCrawler->m_lCrawlInhibitSet);
101 m_pCrawler->SetHoldoff();
103 private:
104 CFolderCrawler* m_pCrawler;
107 #pragma pack(pop, r1)