diff options
| author | The Android Open Source Project <initial-contribution@android.com> | 2009-01-09 17:51:23 -0800 |
|---|---|---|
| committer | The Android Open Source Project <initial-contribution@android.com> | 2009-01-09 17:51:23 -0800 |
| commit | b798689749c64baba81f02e10cf2157c747d6b46 (patch) | |
| tree | da394a395ddb1a6cf69193314846b03fe47a397e /include/utils/RefBase.h | |
| parent | f013e1afd1e68af5e3b868c26a653bbfb39538f8 (diff) | |
| download | frameworks_base-b798689749c64baba81f02e10cf2157c747d6b46.zip frameworks_base-b798689749c64baba81f02e10cf2157c747d6b46.tar.gz frameworks_base-b798689749c64baba81f02e10cf2157c747d6b46.tar.bz2 | |
auto import from //branches/cupcake/...@125939
Diffstat (limited to 'include/utils/RefBase.h')
| -rw-r--r-- | include/utils/RefBase.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/include/utils/RefBase.h b/include/utils/RefBase.h index e37b56f..cbda0fd 100644 --- a/include/utils/RefBase.h +++ b/include/utils/RefBase.h @@ -17,6 +17,7 @@ #ifndef ANDROID_REF_BASE_H #define ANDROID_REF_BASE_H +#include <cutils/atomic.h> #include <utils/TextOutput.h> #include <stdint.h> @@ -142,6 +143,29 @@ private: // --------------------------------------------------------------------------- +template <class T> +class LightRefBase +{ +public: + inline LightRefBase() : mCount(0) { } + inline void incStrong(const void* id) const { + android_atomic_inc(&mCount); + } + inline void decStrong(const void* id) const { + if (android_atomic_dec(&mCount) == 1) { + delete static_cast<const T*>(this); + } + } + +protected: + inline ~LightRefBase() { } + +private: + mutable volatile int32_t mCount; +}; + +// --------------------------------------------------------------------------- + template <typename T> class sp { |
