MCPcopy Create free account
hub / github.com/anjo76/angelscript / GetWeakRefFlag

Method GetWeakRefFlag

sdk/angelscript/source/as_scriptobject.cpp:491–516  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

489}
490
491asILockableSharedBool *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
518void *asCScriptObject::GetUserData(asPWORD type) const
519{

Callers 1

Calls 2

asAcquireExclusiveLockFunction · 0.85
asReleaseExclusiveLockFunction · 0.85

Tested by

no test coverage detected