Home | History | Annotate | Download | only in core
      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_platform_DEFINED
     18 #define SkThread_platform_DEFINED
     19 
     20 #if defined(ANDROID) && !defined(SK_BUILD_FOR_ANDROID_NDK)
     21 
     22 #include <utils/threads.h>
     23 #include <utils/Atomic.h>
     24 
     25 #define sk_atomic_inc(addr)     android_atomic_inc(addr)
     26 #define sk_atomic_dec(addr)     android_atomic_dec(addr)
     27 
     28 class SkMutex : android::Mutex {
     29 public:
     30     // if isGlobal is true, then ignore any errors in the platform-specific
     31     // destructor
     32     SkMutex(bool isGlobal = true) {}
     33     ~SkMutex() {}
     34 
     35     void    acquire() { this->lock(); }
     36     void    release() { this->unlock(); }
     37 };
     38 
     39 #else
     40 
     41 /** Implemented by the porting layer, this function adds 1 to the int specified
     42     by the address (in a thread-safe manner), and returns the previous value.
     43 */
     44 SK_API int32_t sk_atomic_inc(int32_t* addr);
     45 /** Implemented by the porting layer, this function subtracts 1 to the int
     46     specified by the address (in a thread-safe manner), and returns the previous
     47     value.
     48 */
     49 SK_API int32_t sk_atomic_dec(int32_t* addr);
     50 
     51 class SkMutex {
     52 public:
     53     // if isGlobal is true, then ignore any errors in the platform-specific
     54     // destructor
     55     SkMutex(bool isGlobal = true);
     56     ~SkMutex();
     57 
     58     void    acquire();
     59     void    release();
     60 
     61 private:
     62     bool fIsGlobal;
     63     enum {
     64         kStorageIntCount = 64
     65     };
     66     uint32_t    fStorage[kStorageIntCount];
     67 };
     68 
     69 #endif
     70 
     71 #endif
     72