/* -*- 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/. */
// Based on example code from _Programming with POSIX Threads_. Not an actual // test of correctness, but more of a "does this work at all" sort of test.
class RWLockRunnable : public mozilla::Runnable { public:
RWLockRunnable(RWLock* aRWLock, mozilla::Atomic<size_t>* aSharedData)
: mozilla::Runnable("RWLockRunnable"),
mRWLock(aRWLock),
mSharedData(aSharedData) {}
NS_IMETHODIMP
RWLockRunnable::Run() { for (size_t i = 0; i < sOuterIterations; ++i) { if (i % sWriteLockIteration == 0) {
mozilla::AutoWriteLock lock(*mRWLock);
// Loop and try to force other threads to run, but check that our // shared data isn't being modified by them.
size_t initialValue = *mSharedData; for (size_t j = 0; j < sInnerIterations; ++j) {
EXPECT_EQ(initialValue, *mSharedData);
// This is a magic yield call.
PR_Sleep(PR_INTERVAL_NO_WAIT);
}
}
}
for (size_t i = 0; i < sNumThreads; ++i) {
nsCOMPtr<nsIRunnable> event = new RWLockRunnable(&rwlock, &data);
NS_NewNamedThread("RWLockTester", getter_AddRefs(threads[i]), event);
}
// Wait for all the threads to finish. for (size_t i = 0; i < sNumThreads; ++i) {
nsresult rv = threads[i]->Shutdown();
EXPECT_NS_SUCCEEDED(rv);
}
¤ 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.0.5Bemerkung:
¤
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.