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_dec(int32_t*);
20
21class SkMutex {
22public:
23    SkMutex();
24    ~SkMutex();
25
26    void    acquire();
27    void    release();
28};
29
30****************/
31
32class SkAutoMutexAcquire : SkNoncopyable {
33public:
34    explicit SkAutoMutexAcquire(SkBaseMutex& mutex) : fMutex(&mutex)
35    {
36        SkASSERT(fMutex != NULL);
37        mutex.acquire();
38    }
39    /** If the mutex has not been release, release it now.
40    */
41    ~SkAutoMutexAcquire()
42    {
43        if (fMutex)
44            fMutex->release();
45    }
46    /** If the mutex has not been release, release it now.
47    */
48    void release()
49    {
50        if (fMutex)
51        {
52            fMutex->release();
53            fMutex = NULL;
54        }
55    }
56
57private:
58    SkBaseMutex* fMutex;
59};
60
61#endif
62