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

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

Issue 11012013: Hanging resolved (critical sections unlocking) (Closed)
Patch Set: Using CriticalSection class instead Created June 17, 2013, 10:03 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/plugin/PluginFilter.h » ('j') | src/plugin/PluginFilter.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include <fstream> 1 #include <fstream>
2 #include <stdio.h> 2 #include <stdio.h>
3 #include <sstream> 3 #include <sstream>
4 #include <Windows.h> 4 #include <Windows.h>
5 5
6 #include "../shared/Utils.h" 6 #include "../shared/Utils.h"
7 7
8 #include "Debug.h" 8 #include "Debug.h"
9 9
10 #ifdef _DEBUG 10 #ifdef _DEBUG
11 11
12 namespace 12 CriticalSection debugLock;
Wladimir Palant 2013/06/17 12:57:24 IMHO this should be kept inside the anonymous name
13 {
14 class CriticalSection
15 {
16 public:
17 CriticalSection()
18 {
19 InitializeCriticalSection(&section);
20 }
21
22 ~CriticalSection()
23 {
24 DeleteCriticalSection(&section);
25 }
26
27 class Lock
28 {
29 public:
30 Lock(CriticalSection& cs)
31 : section(&cs.section)
32 {
33 EnterCriticalSection(section);
34 }
35
36 ~Lock()
37 {
38 LeaveCriticalSection(section);
39 }
40 private:
41 LPCRITICAL_SECTION section;
42 Lock(const Lock&);
43 Lock& operator=(const Lock&);
44 };
45 private:
46 CRITICAL_SECTION section;
47 CriticalSection(const CriticalSection&);
48 CriticalSection& operator=(const CriticalSection&);
49 };
50
51 CriticalSection debugLock;
52 }
53 13
54 void Debug(const std::string& text) 14 void Debug(const std::string& text)
55 { 15 {
56 SYSTEMTIME st; 16 SYSTEMTIME st;
57 ::GetSystemTime(&st); 17 ::GetSystemTime(&st);
58 18
59 char timeBuf[14]; 19 char timeBuf[14];
60 _snprintf_s(timeBuf, _TRUNCATE, "%02i:%02i:%02i.%03i", st.wHour, st.wMinute, s t.wSecond, st.wMilliseconds); 20 _snprintf_s(timeBuf, _TRUNCATE, "%02i:%02i:%02i.%03i", st.wHour, st.wMinute, s t.wSecond, st.wMilliseconds);
61 21
62 std::wstring filePath = GetAppDataPath() + L"\\debug_engine.txt"; 22 std::wstring filePath = GetAppDataPath() + L"\\debug_engine.txt";
(...skipping 13 matching lines...) Expand all
76 36
77 void DebugException(const std::exception& exception) 37 void DebugException(const std::exception& exception)
78 { 38 {
79 Debug(std::string("An exception occurred: ") + exception.what()); 39 Debug(std::string("An exception occurred: ") + exception.what());
80 } 40 }
81 #else 41 #else
82 void Debug(const std::string& text) {} 42 void Debug(const std::string& text) {}
83 void DebugLastError(const std::string& message) {} 43 void DebugLastError(const std::string& message) {}
84 void DebugException(const std::exception& exception) {} 44 void DebugException(const std::exception& exception) {}
85 #endif // _DEBUG 45 #endif // _DEBUG
OLDNEW
« no previous file with comments | « no previous file | src/plugin/PluginFilter.h » ('j') | src/plugin/PluginFilter.h » ('J')

Powered by Google App Engine
This is Rietveld