Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: src/engine/main.cpp

Issue 10891004: Use a named mutex to avoid race conditions (Closed)
Patch Set: Created June 7, 2013, 8:05 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/shared/Communication.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <AdblockPlus.h> 1 #include <AdblockPlus.h>
2 #include <vector> 2 #include <vector>
3 #include <Windows.h> 3 #include <Windows.h>
4 4
5 #include "../shared/AutoHandle.h" 5 #include "../shared/AutoHandle.h"
6 #include "../shared/Communication.h" 6 #include "../shared/Communication.h"
7 #include "../shared/Utils.h" 7 #include "../shared/Utils.h"
8 #include "../shared/Version.h" 8 #include "../shared/Version.h"
9 #include "Debug.h" 9 #include "Debug.h"
10 10
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 180
181 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo); 181 AdblockPlus::JsEnginePtr jsEngine = AdblockPlus::JsEngine::New(appInfo);
182 std::string dataPath = ToUtf8String(GetAppDataPath()); 182 std::string dataPath = ToUtf8String(GetAppDataPath());
183 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get()) ->SetBasePath(dataPath); 183 dynamic_cast<AdblockPlus::DefaultFileSystem*>(jsEngine->GetFileSystem().get()) ->SetBasePath(dataPath);
184 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE ngine(jsEngine)); 184 std::auto_ptr<AdblockPlus::FilterEngine> filterEngine(new AdblockPlus::FilterE ngine(jsEngine));
185 return filterEngine; 185 return filterEngine;
186 } 186 }
187 187
188 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int) 188 int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
189 { 189 {
190 if (Communication::PipeExists(Communication::pipeName)) 190 AutoHandle mutex(CreateMutexW(0, false, L"AdblockPlusEngine"));
Oleksandr 2013/06/07 14:52:09 Shouldn't this be Global\AdblockPlusEngine?
191 if (!mutex)
192 {
193 DebugLastError("CreateMutex failed");
194 return 1;
195 }
196
197 if (GetLastError() == ERROR_ALREADY_EXISTS)
191 { 198 {
192 DebugLastError("Named pipe exists, another engine instance appears to be run ning"); 199 DebugLastError("Named pipe exists, another engine instance appears to be run ning");
193 return 1; 200 return 1;
194 } 201 }
Wladimir Palant 2013/06/07 14:32:01 Remove the block of code above?
Felix Dahlke 2013/06/07 14:33:25 What in particular? The check for ERROR_ALREADY_EX
Wladimir Palant 2013/06/07 14:46:45 Ok, that debug message is misleading then. How abo
195 202
196 int argc; 203 int argc;
197 LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc); 204 LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
198 std::wstring locale(argc >= 1 ? argv[0] : L""); 205 std::wstring locale(argc >= 1 ? argv[0] : L"");
199 LocalFree(argv); 206 LocalFree(argv);
200 207
201 filterEngine = CreateFilterEngine(locale); 208 filterEngine = CreateFilterEngine(locale);
202 209
203 for (;;) 210 for (;;)
204 { 211 {
(...skipping 13 matching lines...) Expand all
218 } 225 }
219 catch (std::runtime_error e) 226 catch (std::runtime_error e)
220 { 227 {
221 DebugException(e); 228 DebugException(e);
222 return 1; 229 return 1;
223 } 230 }
224 } 231 }
225 232
226 return 0; 233 return 0;
227 } 234 }
OLDNEW
« no previous file with comments | « no previous file | src/shared/Communication.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld