| 489 | } |
| 490 | |
| 491 | asILockableSharedBool *asCScriptObject::GetWeakRefFlag() const |
| 492 | { |
| 493 | // If the object's refCount has already reached zero then the object is already |
| 494 | // about to be destroyed so it's ok to return null if the weakRefFlag doesn't already |
| 495 | // exist |
| 496 | if( (extra && extra->weakRefFlag) || hasRefCountReachedZero ) |
| 497 | return extra->weakRefFlag; |
| 498 | |
| 499 | // Lock globally so no other thread can attempt |
| 500 | // to create a shared bool at the same time. |
| 501 | // TODO: runtime optimize: Instead of locking globally, it would be possible to have |
| 502 | // a critical section per object type. This would reduce the |
| 503 | // chances of two threads lock on the same critical section. |
| 504 | asAcquireExclusiveLock(); |
| 505 | |
| 506 | // Make sure another thread didn't create the |
| 507 | // flag while we waited for the lock |
| 508 | if( !extra ) |
| 509 | extra = asNEW(SExtra); |
| 510 | if( !extra->weakRefFlag ) |
| 511 | extra->weakRefFlag = asNEW(asCLockableSharedBool); |
| 512 | |
| 513 | asReleaseExclusiveLock(); |
| 514 | |
| 515 | return extra->weakRefFlag; |
| 516 | } |
| 517 | |
| 518 | void *asCScriptObject::GetUserData(asPWORD type) const |
| 519 | { |
no test coverage detected