本文整理汇总了C++中atomset::AddPtr::setPinned方法的典型用法代码示例。如果您正苦于以下问题:C++ AddPtr::setPinned方法的具体用法?C++ AddPtr::setPinned怎么用?C++ AddPtr::setPinned使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类atomset::AddPtr
的用法示例。
在下文中一共展示了AddPtr::setPinned方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: lookup
MOZ_ALWAYS_INLINE
static JSAtom*
AtomizeAndCopyChars(ExclusiveContext* cx, const CharT* tbchars, size_t length, PinningBehavior pin)
{
if (JSAtom* s = cx->staticStrings().lookup(tbchars, length))
return s;
AtomHasher::Lookup lookup(tbchars, length);
// Note: when this function is called while the permanent atoms table is
// being initialized (in initializeAtoms()), |permanentAtoms| is not yet
// initialized so this lookup is always skipped. Only once
// transformToPermanentAtoms() is called does |permanentAtoms| get
// initialized and then this lookup will go ahead.
if (cx->isPermanentAtomsInitialized()) {
AtomSet::Ptr pp = cx->permanentAtoms().readonlyThreadsafeLookup(lookup);
if (pp)
return pp->asPtr();
}
AutoLockForExclusiveAccess lock(cx);
AtomSet& atoms = cx->atoms();
AtomSet::AddPtr p = atoms.lookupForAdd(lookup);
if (p) {
JSAtom* atom = p->asPtr();
p->setPinned(bool(pin));
return atom;
}
AutoCompartment ac(cx, cx->atomsCompartment());
JSFlatString* flat = NewStringCopyN<NoGC>(cx, tbchars, length);
if (!flat) {
// Grudgingly forgo last-ditch GC. The alternative would be to release
// the lock, manually GC here, and retry from the top. If you fix this,
// please also fix or comment the similar case in Symbol::new_.
ReportOutOfMemory(cx);
return nullptr;
}
JSAtom* atom = flat->morphAtomizedStringIntoAtom();
// We have held the lock since looking up p, and the operations we've done
// since then can't GC; therefore the atoms table has not been modified and
// p is still valid.
if (!atoms.add(p, AtomStateEntry(atom, bool(pin)))) {
ReportOutOfMemory(cx); /* SystemAllocPolicy does not report OOM. */
return nullptr;
}
return atom;
}