1 2/* 3 * Copyright 2008 The Android Open Source Project 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 10#include <windows.h> 11#include <intrin.h> 12#include "SkThread.h" 13 14//MSDN says in order to declare an interlocked function for use as an 15//intrinsic, include intrin.h and put the function in a #pragma intrinsic 16//directive. 17//The pragma appears to be unnecessary, but doesn't hurt. 18#pragma intrinsic(_InterlockedIncrement, _InterlockedDecrement) 19 20int32_t sk_atomic_inc(int32_t* addr) { 21 // InterlockedIncrement returns the new value, we want to return the old. 22 return _InterlockedIncrement(reinterpret_cast<LONG*>(addr)) - 1; 23} 24 25int32_t sk_atomic_dec(int32_t* addr) { 26 return _InterlockedDecrement(reinterpret_cast<LONG*>(addr)) + 1; 27} 28 29SkMutex::SkMutex() { 30 SK_COMPILE_ASSERT(sizeof(fStorage) > sizeof(CRITICAL_SECTION), 31 NotEnoughSizeForCriticalSection); 32 InitializeCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(&fStorage)); 33} 34 35SkMutex::~SkMutex() { 36 DeleteCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(&fStorage)); 37} 38 39void SkMutex::acquire() { 40 EnterCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(&fStorage)); 41} 42 43void SkMutex::release() { 44 LeaveCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(&fStorage)); 45} 46 47