Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Side by Side Diff: src/ports/SkMutex_win.h

Issue 364473002: Grant independence to SkBaseMutex on Windows. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Even more trivial SkMutex Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkMutex_win_DEFINED 8 #ifndef SkMutex_win_DEFINED
9 #define SkMutex_win_DEFINED 9 #define SkMutex_win_DEFINED
10 10
(...skipping 13 matching lines...) Expand all
24 #ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED 24 #ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
25 # undef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED 25 # undef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED
26 # undef WIN32_LEAN_AND_MEAN 26 # undef WIN32_LEAN_AND_MEAN
27 #endif 27 #endif
28 #ifdef NOMINMAX_WAS_LOCALLY_DEFINED 28 #ifdef NOMINMAX_WAS_LOCALLY_DEFINED
29 # undef NOMINMAX_WAS_LOCALLY_DEFINED 29 # undef NOMINMAX_WAS_LOCALLY_DEFINED
30 # undef NOMINMAX 30 # undef NOMINMAX
31 #endif 31 #endif
32 32
33 // On Windows, SkBaseMutex and SkMutex are the same thing, 33 // On Windows, SkBaseMutex and SkMutex are the same thing,
34 // we can't easily get rid of static initializers. 34 // we can't easily get rid of static initializers. However,
35 class SkMutex { 35 // we preserve the same inheritance pattern as other platforms
36 // so that we can forward-declare cleanly.
37 struct SkBaseMutex {
36 public: 38 public:
37 SkMutex() { 39 SkBaseMutex() {
38 InitializeCriticalSection(&fStorage); 40 InitializeCriticalSection(&fStorage);
39 SkDEBUGCODE(fOwner = 0;) 41 SkDEBUGCODE(fOwner = 0;)
40 } 42 }
41 43
42 ~SkMutex() { 44 ~SkBaseMutex() {
43 SkASSERT(0 == fOwner); 45 SkASSERT(0 == fOwner);
44 DeleteCriticalSection(&fStorage); 46 DeleteCriticalSection(&fStorage);
45 } 47 }
46 48
47 void acquire() { 49 void acquire() {
48 EnterCriticalSection(&fStorage); 50 EnterCriticalSection(&fStorage);
49 SkDEBUGCODE(fOwner = GetCurrentThreadId();) 51 SkDEBUGCODE(fOwner = GetCurrentThreadId();)
50 } 52 }
51 53
52 void release() { 54 void release() {
53 this->assertHeld(); 55 this->assertHeld();
54 SkDEBUGCODE(fOwner = 0;) 56 SkDEBUGCODE(fOwner = 0;)
55 LeaveCriticalSection(&fStorage); 57 LeaveCriticalSection(&fStorage);
56 } 58 }
57 59
58 void assertHeld() { 60 void assertHeld() {
59 SkASSERT(GetCurrentThreadId() == fOwner); 61 SkASSERT(GetCurrentThreadId() == fOwner);
60 } 62 }
61 63
62 private: 64 protected:
63 SkMutex(const SkMutex&);
64 SkMutex& operator=(const SkMutex&);
65
66 CRITICAL_SECTION fStorage; 65 CRITICAL_SECTION fStorage;
67 SkDEBUGCODE(DWORD fOwner;) 66 SkDEBUGCODE(DWORD fOwner;)
67
68 private:
69 SkBaseMutex(const SkBaseMutex&);
70 SkBaseMutex& operator=(const SkBaseMutex&);
68 }; 71 };
69 72
70 typedef SkMutex SkBaseMutex; 73 class SkMutex : public SkBaseMutex { };
71 74
72 // Windows currently provides no documented means of POD initializing a CRITICAL _SECTION. 75 // Windows currently provides no documented means of POD initializing a CRITICAL _SECTION.
73 #define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name 76 #define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name
74 #define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name 77 #define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name
75 78
76 #endif 79 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698