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