michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkMutex_win_DEFINED michael@0: #define SkMutex_win_DEFINED michael@0: michael@0: /** Windows CriticalSection based mutex. */ michael@0: michael@0: #ifndef WIN32_LEAN_AND_MEAN michael@0: # define WIN32_LEAN_AND_MEAN michael@0: # define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED michael@0: #endif michael@0: #ifndef NOMINMAX michael@0: # define NOMINMAX michael@0: # define NOMINMAX_WAS_LOCALLY_DEFINED michael@0: #endif michael@0: # michael@0: #include michael@0: # michael@0: #ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED michael@0: # undef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED michael@0: # undef WIN32_LEAN_AND_MEAN michael@0: #endif michael@0: #ifdef NOMINMAX_WAS_LOCALLY_DEFINED michael@0: # undef NOMINMAX_WAS_LOCALLY_DEFINED michael@0: # undef NOMINMAX michael@0: #endif michael@0: michael@0: // On Windows, SkBaseMutex and SkMutex are the same thing, michael@0: // we can't easily get rid of static initializers. michael@0: class SkMutex { michael@0: public: michael@0: SkMutex() { michael@0: InitializeCriticalSection(&fStorage); michael@0: } michael@0: michael@0: ~SkMutex() { michael@0: DeleteCriticalSection(&fStorage); michael@0: } michael@0: michael@0: void acquire() { michael@0: EnterCriticalSection(&fStorage); michael@0: } michael@0: michael@0: void release() { michael@0: LeaveCriticalSection(&fStorage); michael@0: } michael@0: michael@0: private: michael@0: SkMutex(const SkMutex&); michael@0: SkMutex& operator=(const SkMutex&); michael@0: michael@0: CRITICAL_SECTION fStorage; michael@0: }; michael@0: michael@0: typedef SkMutex SkBaseMutex; michael@0: michael@0: // Windows currently provides no documented means of POD initializing a CRITICAL_SECTION. michael@0: #define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name michael@0: #define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name michael@0: michael@0: #endif