remove duplicates from the list
[TortoiseGit.git] / src / TGitCache / FolderCrawler.h
blobbabf949949997b7ff74b7e9973632f1066c2c4bd
1 // TortoiseGit - a Windows shell extension for easy version control
3 // External Cache Copyright (C) 2005-2007, 2009-2011 TortoiseSVN
4 // Copyright (C) 2008-2012 - 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 "SmartHandle.h"
25 #include "UniqueQueue.h"
26 #include <set>
27 //////////////////////////////////////////////////////////////////////////
31 #pragma pack(push, r1, 16)
33 /**
34 * \ingroup TSVNCache
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.
38 class CFolderCrawler
40 public:
41 CFolderCrawler(void);
42 ~CFolderCrawler(void);
44 public:
45 void Initialise();
46 void AddDirectoryForUpdate(const CTGitPath& path);
47 void AddPathForUpdate(const CTGitPath& path);
48 void Stop();
49 bool SetHoldoff(DWORD milliseconds = 100);
50 void BlockPath(const CTGitPath& path, DWORD ticks = 0);
51 private:
52 static unsigned int __stdcall ThreadEntry(void* pContext);
53 void WorkerThread();
55 private:
56 CComAutoCriticalSection m_critSec;
57 CAutoGeneralHandle m_hThread;
58 UniqueQueue<CTGitPath> m_foldersToUpdate;
59 UniqueQueue<CTGitPath> m_pathsToUpdate;
61 void RemoveDuplicate(std::deque<CTGitPath> &list,const CTGitPath &path);
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;
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 long m_crawlHoldoffReleasesAt;
76 bool m_bItemsAddedSinceLastCrawl;
77 bool m_bPathsAddedSinceLastCrawl;
79 CTGitPath m_blockedPath;
80 DWORD m_blockReleasesAt;
81 bool m_bRun;
84 friend class CCrawlInhibitor;
88 //////////////////////////////////////////////////////////////////////////
91 class CCrawlInhibitor
93 private:
94 CCrawlInhibitor(); // Not defined
95 public:
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);
104 ~CCrawlInhibitor()
106 ::InterlockedDecrement(&m_pCrawler->m_lCrawlInhibitSet);
107 m_pCrawler->SetHoldoff();
109 private:
110 CFolderCrawler* m_pCrawler;
113 #pragma pack(pop, r1)