/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
EXPECT_EQ(count, NS_GetNumberOfAtoms());
} #ifndef DEBUG // Don't run this test in debug builds as that intentionally asserts. for (unsignedint i = 0; i < std::size(Invalid8Strings); ++i) {
nsrefcnt count = NS_GetNumberOfAtoms();
staticbool isStaticAtom(nsAtom* atom) { // Don't use logic && in order to ensure that all addrefs/releases are always // run, even if one of the tests fail. This allows us to run this code on a // non-static atom without affecting its refcount. bool rv = (atom->AddRef() == 2);
rv &= (atom->AddRef() == 2);
rv &= (atom->AddRef() == 2);
staticvoid AccessAtoms(void*) { for (int i = 0; i < 10000; i++) {
RefPtr<nsAtom> atom = NS_Atomize(u"A Testing Atom");
}
}
TEST(Atoms, ConcurrentAccessing)
{ staticconst size_t kThreadCount = 4; // Force a GC before so that we don't have any unused atom.
NS_GetNumberOfAtoms();
EXPECT_EQ(NS_GetUnusedAtomCount(), int32_t(0));
// Spawn PRThreads to do the concurrent atom access, to make sure we don't // spin the main thread event loop. Spinning the event loop may run a task // that uses an atom, leading to a false positive test failure.
PRThread* threads[kThreadCount]; for (size_t i = 0; i < kThreadCount; i++) {
threads[i] = PR_CreateThread(PR_USER_THREAD, AccessAtoms, nullptr,
PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD,
PR_JOINABLE_THREAD, 0);
EXPECT_TRUE(threads[i]);
}
for (size_t i = 0; i < kThreadCount; i++) {
EXPECT_EQ(PR_SUCCESS, PR_JoinThread(threads[i]));
}
// We should have one unused atom from this test.
EXPECT_EQ(NS_GetUnusedAtomCount(), int32_t(1));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.