Grant independence to SkBaseMutex on Windows.

Under POSIX, class SkMutex inherits from struct SkBaseMutex.
Since we can't have a POD mutex on Windows, we used to just
typedef SkMutex SkBaseMutex there. However, that makes it
impossible to forward-declare SkBaseMutex consistently across
platforms. With this CL we declare an empty struct SkBaseMutex
on Windows, which should have 0 cost but make the compiler happy.

R=bungeman@google.com, mtklein@google.com, tomhudson@google.com, bungeman, mtklein
BUG=skia:

Author: tomhudson@chromium.org

Review URL: https://codereview.chromium.org/364473002
This commit is contained in:
tomhudson 2014-07-01 06:26:48 -07:00 committed by Commit bot
parent 4a2489f7bb
commit cad0cb2a2d

View File

@ -31,15 +31,17 @@
#endif #endif
// On Windows, SkBaseMutex and SkMutex are the same thing, // On Windows, SkBaseMutex and SkMutex are the same thing,
// we can't easily get rid of static initializers. // we can't easily get rid of static initializers. However,
class SkMutex { // we preserve the same inheritance pattern as other platforms
// so that we can forward-declare cleanly.
struct SkBaseMutex {
public: public:
SkMutex() { SkBaseMutex() {
InitializeCriticalSection(&fStorage); InitializeCriticalSection(&fStorage);
SkDEBUGCODE(fOwner = 0;) SkDEBUGCODE(fOwner = 0;)
} }
~SkMutex() { ~SkBaseMutex() {
SkASSERT(0 == fOwner); SkASSERT(0 == fOwner);
DeleteCriticalSection(&fStorage); DeleteCriticalSection(&fStorage);
} }
@ -59,15 +61,16 @@ public:
SkASSERT(GetCurrentThreadId() == fOwner); SkASSERT(GetCurrentThreadId() == fOwner);
} }
private: protected:
SkMutex(const SkMutex&);
SkMutex& operator=(const SkMutex&);
CRITICAL_SECTION fStorage; CRITICAL_SECTION fStorage;
SkDEBUGCODE(DWORD fOwner;) SkDEBUGCODE(DWORD fOwner;)
private:
SkBaseMutex(const SkBaseMutex&);
SkBaseMutex& operator=(const SkBaseMutex&);
}; };
typedef SkMutex SkBaseMutex; class SkMutex : public SkBaseMutex { };
// Windows currently provides no documented means of POD initializing a CRITICAL_SECTION. // Windows currently provides no documented means of POD initializing a CRITICAL_SECTION.
#define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name #define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name