Home | History | Annotate | Download | only in core
      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     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 
     57 private:
     58     SkBaseMutex* fMutex;
     59 };
     60 
     61 #endif
     62