1/* 2 * Copyright (C) 2006 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef SkThread_DEFINED 18#define SkThread_DEFINED 19 20#include "SkTypes.h" 21#include "SkThread_platform.h" 22 23/****** SkThread_platform needs to define the following... 24 25int32_t sk_atomic_inc(int32_t*); 26int32_t sk_atomic_dec(int32_t*); 27 28class SkMutex { 29public: 30 SkMutex(); 31 ~SkMutex(); 32 33 void acquire(); 34 void release(); 35}; 36 37****************/ 38 39class SkAutoMutexAcquire : SkNoncopyable { 40public: 41 explicit SkAutoMutexAcquire(SkMutex& mutex) : fMutex(&mutex) 42 { 43 SkASSERT(fMutex != NULL); 44 mutex.acquire(); 45 } 46 /** If the mutex has not been release, release it now. 47 */ 48 ~SkAutoMutexAcquire() 49 { 50 if (fMutex) 51 fMutex->release(); 52 } 53 /** If the mutex has not been release, release it now. 54 */ 55 void release() 56 { 57 if (fMutex) 58 { 59 fMutex->release(); 60 fMutex = NULL; 61 } 62 } 63 64private: 65 SkMutex* fMutex; 66}; 67 68#endif 69