/* -*- 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/. */
void Delay() { // On Windows and x86 Android, the timer resolution is so bad that, even if // we used `timeBeginPeriod(1)`, any nonzero sleep from the test's inner loops // would make this program take far too long. #ifdef _WIN32
Sleep(0); #elifdefined(ANDROID)
std::this_thread::sleep_for(std::chrono::microseconds(0)); #else
std::this_thread::sleep_for(std::chrono::microseconds(10)); #endif
}
// Enqueue with a different thread. We reset the thread ID in the ring buffer, // this should work.
std::thread p2([&ring] {
ring.ResetProducerThreadId();
std::unique_ptr<float[]> inBuffer(newfloat[ENQUEUE_SIZE]); int rv = ring.Enqueue(inBuffer.get(), ENQUEUE_SIZE);
MOZ_RELEASE_ASSERT(rv > 0);
});
p2.join();
// Dequeue with a different thread. We reset the thread ID in the ring buffer, // this should work.
std::thread c2([&ring] {
ring.ResetConsumerThreadId();
std::unique_ptr<float[]> outBuffer(newfloat[ENQUEUE_SIZE]); int rv = ring.Dequeue(outBuffer.get(), ENQUEUE_SIZE);
MOZ_RELEASE_ASSERT(rv > 0);
});
c2.join();
// Similarly, but do the Enqueues without a Dequeue in between, since a // Dequeue could affect memory ordering.
std::thread p4;
std::thread p3([&] {
ring.ResetProducerThreadId();
std::unique_ptr<float[]> inBuffer(newfloat[ENQUEUE_SIZE]); int rv = ring.Enqueue(inBuffer.get(), ENQUEUE_SIZE);
MOZ_RELEASE_ASSERT(rv > 0);
p4 = std::thread([&ring] {
ring.ResetProducerThreadId();
std::unique_ptr<float[]> inBuffer(newfloat[ENQUEUE_SIZE]); int rv = ring.Enqueue(inBuffer.get(), ENQUEUE_SIZE);
MOZ_RELEASE_ASSERT(rv > 0);
});
});
for (uint32_t i = minCapacity; i < maxCapacity; i += capacityIncrement) {
TestRing<uint32_t>(i);
TestRingMultiThread<uint32_t>(i);
TestRing<float>(i);
TestRingMultiThread<float>(i);
}
TestResetAPI();
TestMove();
return 0;
}
¤ Dauer der Verarbeitung: 0.15 Sekunden
(vorverarbeitet)
¤
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.