1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/ports/SkMutex_win.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,66 @@ 1.4 +/* 1.5 + * Copyright 2013 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef SkMutex_win_DEFINED 1.12 +#define SkMutex_win_DEFINED 1.13 + 1.14 +/** Windows CriticalSection based mutex. */ 1.15 + 1.16 +#ifndef WIN32_LEAN_AND_MEAN 1.17 +# define WIN32_LEAN_AND_MEAN 1.18 +# define WIN32_IS_MEAN_WAS_LOCALLY_DEFINED 1.19 +#endif 1.20 +#ifndef NOMINMAX 1.21 +# define NOMINMAX 1.22 +# define NOMINMAX_WAS_LOCALLY_DEFINED 1.23 +#endif 1.24 +# 1.25 +#include <windows.h> 1.26 +# 1.27 +#ifdef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED 1.28 +# undef WIN32_IS_MEAN_WAS_LOCALLY_DEFINED 1.29 +# undef WIN32_LEAN_AND_MEAN 1.30 +#endif 1.31 +#ifdef NOMINMAX_WAS_LOCALLY_DEFINED 1.32 +# undef NOMINMAX_WAS_LOCALLY_DEFINED 1.33 +# undef NOMINMAX 1.34 +#endif 1.35 + 1.36 +// On Windows, SkBaseMutex and SkMutex are the same thing, 1.37 +// we can't easily get rid of static initializers. 1.38 +class SkMutex { 1.39 +public: 1.40 + SkMutex() { 1.41 + InitializeCriticalSection(&fStorage); 1.42 + } 1.43 + 1.44 + ~SkMutex() { 1.45 + DeleteCriticalSection(&fStorage); 1.46 + } 1.47 + 1.48 + void acquire() { 1.49 + EnterCriticalSection(&fStorage); 1.50 + } 1.51 + 1.52 + void release() { 1.53 + LeaveCriticalSection(&fStorage); 1.54 + } 1.55 + 1.56 +private: 1.57 + SkMutex(const SkMutex&); 1.58 + SkMutex& operator=(const SkMutex&); 1.59 + 1.60 + CRITICAL_SECTION fStorage; 1.61 +}; 1.62 + 1.63 +typedef SkMutex SkBaseMutex; 1.64 + 1.65 +// Windows currently provides no documented means of POD initializing a CRITICAL_SECTION. 1.66 +#define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name 1.67 +#define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name 1.68 + 1.69 +#endif