Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 | #include "rsObjectBase.h" |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 18 | #include "rsContext.h" |
Jason Sams | 84bf95d | 2015-04-09 14:36:37 -0700 | [diff] [blame] | 19 | #include "rsDebugHelper.h" |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 20 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 21 | using namespace android; |
| 22 | using namespace android::renderscript; |
| 23 | |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 24 | pthread_mutex_t ObjectBase::gObjectInitMutex = PTHREAD_MUTEX_INITIALIZER; |
| 25 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 26 | ObjectBase::ObjectBase(Context *rsc) { |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 27 | mUserRefCount = 0; |
| 28 | mSysRefCount = 0; |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 29 | mRSC = rsc; |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 30 | mNext = nullptr; |
| 31 | mPrev = nullptr; |
| 32 | mDH = nullptr; |
| 33 | mName = nullptr; |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 34 | |
Jason Sams | 84bf95d | 2015-04-09 14:36:37 -0700 | [diff] [blame] | 35 | if (gDebugStacks || gDebugReferences || gDebugLeaks) { |
| 36 | mDH = new DebugHelper(); |
| 37 | } |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 38 | |
| 39 | rsAssert(rsc); |
| 40 | add(); |
Jason Sams | 84bf95d | 2015-04-09 14:36:37 -0700 | [diff] [blame] | 41 | |
| 42 | if (gDebugLifetime || gDebugReferences) { |
| 43 | ALOGV("ObjectBase constructed %p", this); |
| 44 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 45 | } |
| 46 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 47 | ObjectBase::~ObjectBase() { |
Jason Sams | 84bf95d | 2015-04-09 14:36:37 -0700 | [diff] [blame] | 48 | if (gDebugLifetime || gDebugReferences) { |
| 49 | ALOGV("ObjectBase destroyed %p refs %i %i", this, mUserRefCount, mSysRefCount); |
| 50 | } |
| 51 | |
| 52 | if (gDebugStacks || gDebugReferences || gDebugLeaks) { |
| 53 | if (gDebugStacks || gDebugReferences) { |
| 54 | mDH->dump(); |
| 55 | } |
| 56 | delete mDH; |
| 57 | mDH = nullptr; |
| 58 | } |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 59 | |
Stephen Hines | b0934b6 | 2013-07-03 17:27:38 -0700 | [diff] [blame] | 60 | free(const_cast<char *>(mName)); |
| 61 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 62 | if (mPrev || mNext) { |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 63 | // While the normal practice is to call remove before we call |
| 64 | // delete. Its possible for objects without a re-use list |
| 65 | // for avoiding duplication to be created on the stack. In those |
| 66 | // cases we need to remove ourself here. |
| 67 | asyncLock(); |
| 68 | remove(); |
| 69 | asyncUnlock(); |
| 70 | } |
| 71 | |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 72 | rsAssert(!mUserRefCount); |
| 73 | rsAssert(!mSysRefCount); |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 74 | } |
| 75 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 76 | void ObjectBase::dumpLOGV(const char *op) const { |
Stephen Hines | b0934b6 | 2013-07-03 17:27:38 -0700 | [diff] [blame] | 77 | if (mName) { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 78 | ALOGV("%s RSobj %p, name %s, refs %i,%i links %p,%p,%p", |
Stephen Hines | b0934b6 | 2013-07-03 17:27:38 -0700 | [diff] [blame] | 79 | op, this, mName, mUserRefCount, mSysRefCount, mNext, mPrev, mRSC); |
Jason Sams | f2649a9 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 80 | } else { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 81 | ALOGV("%s RSobj %p, no-name, refs %i,%i links %p,%p,%p", |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 82 | op, this, mUserRefCount, mSysRefCount, mNext, mPrev, mRSC); |
Jason Sams | f2649a9 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 83 | } |
| 84 | } |
| 85 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 86 | void ObjectBase::incUserRef() const { |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 87 | __sync_fetch_and_add(&mUserRefCount, 1); |
Jason Sams | 84bf95d | 2015-04-09 14:36:37 -0700 | [diff] [blame] | 88 | if (gDebugReferences) { |
| 89 | ALOGV("ObjectBase %p incU ref %i, %i", this, mUserRefCount, mSysRefCount); |
| 90 | } |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 93 | void ObjectBase::incSysRef() const { |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 94 | __sync_fetch_and_add(&mSysRefCount, 1); |
Jason Sams | 84bf95d | 2015-04-09 14:36:37 -0700 | [diff] [blame] | 95 | if (gDebugReferences) { |
| 96 | ALOGV("ObjectBase %p incS ref %i, %i", this, mUserRefCount, mSysRefCount); |
| 97 | } |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 98 | } |
| 99 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 100 | void ObjectBase::preDestroy() const { |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 101 | } |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 102 | |
Jason Sams | c7cec1e | 2011-08-18 18:01:33 -0700 | [diff] [blame] | 103 | bool ObjectBase::freeChildren() { |
| 104 | return false; |
| 105 | } |
| 106 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 107 | bool ObjectBase::checkDelete(const ObjectBase *ref) { |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 108 | if (!ref) { |
| 109 | return false; |
| 110 | } |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 111 | |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 112 | asyncLock(); |
| 113 | // This lock protects us against the non-RS threads changing |
| 114 | // the ref counts. At this point we should be the only thread |
| 115 | // working on them. |
| 116 | if (ref->mUserRefCount || ref->mSysRefCount) { |
| 117 | asyncUnlock(); |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | ref->remove(); |
| 122 | // At this point we can unlock because there should be no possible way |
| 123 | // for another thread to reference this object. |
| 124 | ref->preDestroy(); |
| 125 | asyncUnlock(); |
| 126 | delete ref; |
| 127 | return true; |
| 128 | } |
| 129 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 130 | bool ObjectBase::decUserRef() const { |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 131 | rsAssert(mUserRefCount > 0); |
Jason Sams | 84bf95d | 2015-04-09 14:36:37 -0700 | [diff] [blame] | 132 | if (gDebugReferences) { |
| 133 | ALOGV("ObjectBase %p decU ref %i, %i", this, mUserRefCount, mSysRefCount); |
| 134 | if (mUserRefCount <= 0) { |
| 135 | mDH->dump(); |
| 136 | } |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 137 | } |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 138 | |
| 139 | |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 140 | if ((__sync_fetch_and_sub(&mUserRefCount, 1) <= 1)) { |
| 141 | __sync_synchronize(); |
| 142 | if (mSysRefCount <= 0) { |
| 143 | return checkDelete(this); |
| 144 | } |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 145 | } |
| 146 | return false; |
| 147 | } |
| 148 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 149 | bool ObjectBase::zeroUserRef() const { |
Jason Sams | 84bf95d | 2015-04-09 14:36:37 -0700 | [diff] [blame] | 150 | if (gDebugReferences) { |
| 151 | ALOGV("ObjectBase %p zeroU ref %i, %i", this, mUserRefCount, mSysRefCount); |
| 152 | } |
| 153 | |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 154 | __sync_and_and_fetch(&mUserRefCount, 0); |
Stephen Hines | 61c8695 | 2013-04-09 17:34:43 -0700 | [diff] [blame] | 155 | if (mSysRefCount <= 0) { |
| 156 | return checkDelete(this); |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 157 | } |
| 158 | return false; |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 161 | bool ObjectBase::decSysRef() const { |
Jason Sams | 84bf95d | 2015-04-09 14:36:37 -0700 | [diff] [blame] | 162 | if (gDebugReferences) { |
| 163 | ALOGV("ObjectBase %p decS ref %i, %i", this, mUserRefCount, mSysRefCount); |
| 164 | } |
| 165 | |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 166 | rsAssert(mSysRefCount > 0); |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 167 | if ((__sync_fetch_and_sub(&mSysRefCount, 1) <= 1)) { |
| 168 | __sync_synchronize(); |
| 169 | if (mUserRefCount <= 0) { |
| 170 | return checkDelete(this); |
| 171 | } |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 172 | } |
| 173 | return false; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 176 | void ObjectBase::setName(const char *name) { |
Stephen Hines | b0934b6 | 2013-07-03 17:27:38 -0700 | [diff] [blame] | 177 | mName = strdup(name); |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 178 | } |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 179 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 180 | void ObjectBase::setName(const char *name, uint32_t len) { |
Stephen Hines | b0934b6 | 2013-07-03 17:27:38 -0700 | [diff] [blame] | 181 | char *c = (char*)calloc(len + 1, sizeof(char)); |
| 182 | rsAssert(c); |
| 183 | memcpy(c, name, len); |
| 184 | mName = c; |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 185 | } |
| 186 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 187 | void ObjectBase::asyncLock() { |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 188 | pthread_mutex_lock(&gObjectInitMutex); |
| 189 | } |
| 190 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 191 | void ObjectBase::asyncUnlock() { |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 192 | pthread_mutex_unlock(&gObjectInitMutex); |
| 193 | } |
| 194 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 195 | void ObjectBase::add() const { |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 196 | asyncLock(); |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 197 | |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 198 | rsAssert(!mNext); |
| 199 | rsAssert(!mPrev); |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 200 | mNext = mRSC->mObjHead; |
| 201 | if (mRSC->mObjHead) { |
| 202 | mRSC->mObjHead->mPrev = this; |
| 203 | } |
| 204 | mRSC->mObjHead = this; |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 205 | |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 206 | asyncUnlock(); |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 209 | void ObjectBase::remove() const { |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 210 | if (!mRSC) { |
| 211 | rsAssert(!mPrev); |
| 212 | rsAssert(!mNext); |
| 213 | return; |
| 214 | } |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 215 | |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 216 | if (mRSC->mObjHead == this) { |
| 217 | mRSC->mObjHead = mNext; |
| 218 | } |
| 219 | if (mPrev) { |
| 220 | mPrev->mNext = mNext; |
| 221 | } |
| 222 | if (mNext) { |
| 223 | mNext->mPrev = mPrev; |
| 224 | } |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 225 | mPrev = nullptr; |
| 226 | mNext = nullptr; |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 229 | void ObjectBase::zeroAllUserRef(Context *rsc) { |
Jason Sams | 84bf95d | 2015-04-09 14:36:37 -0700 | [diff] [blame] | 230 | if (gDebugReferences || gDebugLeaks) { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 231 | ALOGV("Forcing release of all outstanding user refs."); |
Jason Sams | 1fddd90 | 2009-09-25 15:25:00 -0700 | [diff] [blame] | 232 | } |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 233 | |
| 234 | // This operation can be slow, only to be called during context cleanup. |
| 235 | const ObjectBase * o = rsc->mObjHead; |
| 236 | while (o) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 237 | //ALOGE("o %p", o); |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 238 | if (o->zeroUserRef()) { |
| 239 | // deleted the object and possibly others, restart from head. |
| 240 | o = rsc->mObjHead; |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 241 | //ALOGE("o head %p", o); |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 242 | } else { |
| 243 | o = o->mNext; |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 244 | //ALOGE("o next %p", o); |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 245 | } |
| 246 | } |
Jason Sams | f2649a9 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 247 | |
Jason Sams | 84bf95d | 2015-04-09 14:36:37 -0700 | [diff] [blame] | 248 | if (gDebugReferences || gDebugLeaks) { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 249 | ALOGV("Objects remaining."); |
Jason Sams | 25afc00 | 2009-11-19 13:08:17 -0800 | [diff] [blame] | 250 | dumpAll(rsc); |
Jason Sams | f2649a9 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 251 | } |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Jason Sams | c7cec1e | 2011-08-18 18:01:33 -0700 | [diff] [blame] | 254 | void ObjectBase::freeAllChildren(Context *rsc) { |
Jason Sams | 84bf95d | 2015-04-09 14:36:37 -0700 | [diff] [blame] | 255 | if (gDebugReferences) { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 256 | ALOGV("Forcing release of all child objects."); |
Jason Sams | c7cec1e | 2011-08-18 18:01:33 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | // This operation can be slow, only to be called during context cleanup. |
| 260 | ObjectBase * o = (ObjectBase *)rsc->mObjHead; |
| 261 | while (o) { |
| 262 | if (o->freeChildren()) { |
| 263 | // deleted ref to self and possibly others, restart from head. |
| 264 | o = (ObjectBase *)rsc->mObjHead; |
| 265 | } else { |
| 266 | o = (ObjectBase *)o->mNext; |
| 267 | } |
| 268 | } |
| 269 | |
Jason Sams | 84bf95d | 2015-04-09 14:36:37 -0700 | [diff] [blame] | 270 | if (gDebugReferences) { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 271 | ALOGV("Objects remaining."); |
Jason Sams | c7cec1e | 2011-08-18 18:01:33 -0700 | [diff] [blame] | 272 | dumpAll(rsc); |
| 273 | } |
| 274 | } |
| 275 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 276 | void ObjectBase::dumpAll(Context *rsc) { |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 277 | asyncLock(); |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 278 | |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 279 | ALOGV("Dumping all objects"); |
Jason Sams | 25afc00 | 2009-11-19 13:08:17 -0800 | [diff] [blame] | 280 | const ObjectBase * o = rsc->mObjHead; |
| 281 | while (o) { |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 282 | ALOGV(" Object %p", o); |
Jason Sams | 25afc00 | 2009-11-19 13:08:17 -0800 | [diff] [blame] | 283 | o->dumpLOGV(" "); |
Jason Sams | 84bf95d | 2015-04-09 14:36:37 -0700 | [diff] [blame] | 284 | if (o->mDH != nullptr) { |
| 285 | o->mDH->dump(); |
| 286 | } |
Jason Sams | 25afc00 | 2009-11-19 13:08:17 -0800 | [diff] [blame] | 287 | o = o->mNext; |
Jason Sams | c21cf40 | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 288 | } |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 289 | |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 290 | asyncUnlock(); |
Jason Sams | c21cf40 | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 291 | } |
| 292 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 293 | bool ObjectBase::isValid(const Context *rsc, const ObjectBase *obj) { |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 294 | asyncLock(); |
Jason Sams | 2353ae3 | 2010-10-14 17:48:46 -0700 | [diff] [blame] | 295 | |
Jason Sams | 605048a | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 296 | const ObjectBase * o = rsc->mObjHead; |
| 297 | while (o) { |
| 298 | if (o == obj) { |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 299 | asyncUnlock(); |
Jason Sams | 605048a | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 300 | return true; |
| 301 | } |
| 302 | o = o->mNext; |
| 303 | } |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 304 | asyncUnlock(); |
Jason Sams | 605048a | 2010-09-30 18:15:52 -0700 | [diff] [blame] | 305 | return false; |
| 306 | } |
Jason Sams | a36c50a | 2014-06-17 12:06:06 -0700 | [diff] [blame] | 307 | |
| 308 | void ObjectBase::callUpdateCacheObject(const Context *rsc, void *dstObj) const { |
| 309 | //ALOGE("ObjectBase::callUpdateCacheObject %p %p", this, dstObj); |
| 310 | *((const void **)dstObj) = this; |
| 311 | } |
| 312 | |