TortoiseSVN -> TortoiseGit
[TortoiseGit.git] / src / TGitCache / FolderCrawler.h
blob6f5ffee666d150d7375f95bba5ab3d5b52466fbe
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.
20 #pragma once
22 #include "TGitPath.h"
23 #include "CacheInterface.h"
24 #include <set>
25 //////////////////////////////////////////////////////////////////////////
29 #pragma pack(push, r1, 16)
31 /**
32 * \ingroup TSVNCache
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.
36 class CFolderCrawler
38 public:
39 CFolderCrawler(void);
40 ~CFolderCrawler(void);
42 public:
43 void Initialise();
44 void AddDirectoryForUpdate(const CTGitPath& path);
45 void AddPathForUpdate(const CTGitPath& path);
46 void Stop();
47 bool SetHoldoff(DWORD milliseconds = 100);
48 void BlockPath(const CTGitPath& path, DWORD ticks = 0);
49 private:
50 static unsigned int __stdcall ThreadEntry(void* pContext);
51 void WorkerThread();
53 private:
54 CComAutoCriticalSection m_critSec;
55 HANDLE m_hThread;
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;
62 HANDLE m_hWakeEvent;
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;
79 bool m_bRun;
82 friend class CCrawlInhibitor;
86 //////////////////////////////////////////////////////////////////////////
89 class CCrawlInhibitor
91 private:
92 CCrawlInhibitor(); // Not defined
93 public:
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);
102 ~CCrawlInhibitor()
104 ::InterlockedDecrement(&m_pCrawler->m_lCrawlInhibitSet);
105 m_pCrawler->SetHoldoff();
107 private:
108 CFolderCrawler* m_pCrawler;
111 #pragma pack(pop, r1)