// this function may be called from multiple threads nsHttpAtom nsHttp::ResolveAtom(const char *str) { nsHttpAtom atom = { nsnull }; if (!str || !sAtomTable.ops) return atom; nsAutoLock lock(sLock); PLDHashEntryStub *stub = reinterpret_cast<PLDHashEntryStub *> (PL_DHashTableOperate(&sAtomTable, str, PL_DHASH_ADD)); if (!stub) return atom; // out of memory if (stub->key) { atom._val = reinterpret_cast<const char *>(stub->key); return atom; } // if the atom could not be found in the atom table, then we'll go // and allocate a new atom on the heap. HttpHeapAtom *heapAtom = NewHeapAtom(str); if (!heapAtom) return atom; // out of memory stub->key = atom._val = heapAtom->value; return atom; }
// this function may be called from multiple threads nsHttpAtom nsHttp::ResolveAtom(const char *str) { nsHttpAtom atom = { nullptr }; if (!str || !sAtomTable) return atom; MutexAutoLock lock(*sLock); auto stub = static_cast<PLDHashEntryStub*>(sAtomTable->Add(str, fallible)); if (!stub) return atom; // out of memory if (stub->key) { atom._val = reinterpret_cast<const char *>(stub->key); return atom; } // if the atom could not be found in the atom table, then we'll go // and allocate a new atom on the heap. HttpHeapAtom *heapAtom = NewHeapAtom(str); if (!heapAtom) return atom; // out of memory stub->key = atom._val = heapAtom->value; return atom; }