1 2/* 3 * Copyright 2006 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#ifndef SkThread_DEFINED 11#define SkThread_DEFINED 12 13#include "SkTypes.h" 14#include "SkThread_platform.h" 15 16/****** SkThread_platform needs to define the following... 17 18int32_t sk_atomic_inc(int32_t*); 19int32_t sk_atomic_add(int32_t*, int32_t); 20int32_t sk_atomic_dec(int32_t*); 21int32_t sk_atomic_conditional_inc(int32_t*); 22 23class SkMutex { 24public: 25 SkMutex(); 26 ~SkMutex(); 27 28 void acquire(); 29 void release(); 30}; 31 32****************/ 33 34class SkAutoMutexAcquire : SkNoncopyable { 35public: 36 explicit SkAutoMutexAcquire(SkBaseMutex& mutex) : fMutex(&mutex) { 37 SkASSERT(fMutex != NULL); 38 mutex.acquire(); 39 } 40 41 SkAutoMutexAcquire(SkBaseMutex* mutex) : fMutex(mutex) { 42 if (mutex) { 43 mutex->acquire(); 44 } 45 } 46 47 /** If the mutex has not been release, release it now. 48 */ 49 ~SkAutoMutexAcquire() { 50 if (fMutex) { 51 fMutex->release(); 52 } 53 } 54 55 /** If the mutex has not been release, release it now. 56 */ 57 void release() { 58 if (fMutex) { 59 fMutex->release(); 60 fMutex = NULL; 61 } 62 } 63 64private: 65 SkBaseMutex* fMutex; 66}; 67#define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) 68 69#endif 70