2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2006 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkThread_platform_DEFINED
|
|
|
|
#define SkThread_platform_DEFINED
|
|
|
|
|
2010-12-20 18:26:13 +00:00
|
|
|
#if defined(ANDROID) && !defined(SK_BUILD_FOR_ANDROID_NDK)
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
#include <utils/threads.h>
|
|
|
|
#include <utils/Atomic.h>
|
|
|
|
|
|
|
|
#define sk_atomic_inc(addr) android_atomic_inc(addr)
|
|
|
|
#define sk_atomic_dec(addr) android_atomic_dec(addr)
|
|
|
|
|
|
|
|
class SkMutex : android::Mutex {
|
|
|
|
public:
|
|
|
|
// if isGlobal is true, then ignore any errors in the platform-specific
|
|
|
|
// destructor
|
|
|
|
SkMutex(bool isGlobal = true) {}
|
|
|
|
~SkMutex() {}
|
|
|
|
|
|
|
|
void acquire() { this->lock(); }
|
|
|
|
void release() { this->unlock(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/** Implemented by the porting layer, this function adds 1 to the int specified
|
|
|
|
by the address (in a thread-safe manner), and returns the previous value.
|
|
|
|
*/
|
2011-04-26 20:06:08 +00:00
|
|
|
SK_API int32_t sk_atomic_inc(int32_t* addr);
|
2008-12-17 15:59:43 +00:00
|
|
|
/** Implemented by the porting layer, this function subtracts 1 to the int
|
|
|
|
specified by the address (in a thread-safe manner), and returns the previous
|
|
|
|
value.
|
|
|
|
*/
|
2011-04-26 20:06:08 +00:00
|
|
|
SK_API int32_t sk_atomic_dec(int32_t* addr);
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
class SkMutex {
|
|
|
|
public:
|
|
|
|
// if isGlobal is true, then ignore any errors in the platform-specific
|
|
|
|
// destructor
|
|
|
|
SkMutex(bool isGlobal = true);
|
|
|
|
~SkMutex();
|
|
|
|
|
|
|
|
void acquire();
|
|
|
|
void release();
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool fIsGlobal;
|
|
|
|
enum {
|
2010-05-18 21:23:30 +00:00
|
|
|
kStorageIntCount = 64
|
2008-12-17 15:59:43 +00:00
|
|
|
};
|
|
|
|
uint32_t fStorage[kStorageIntCount];
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|