2 * Copyright 2012 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
9 #include "SkThreadUtils.h"
16 unsigned int processorAffinity;
19 static int32_t base = 0;
21 static AddInfo gAdds[] = {
27 static void addABunchOfTimes(void* data) {
28 AddInfo* addInfo = static_cast<AddInfo*>(data);
29 for (int i = 0; i < addInfo->timesToAdd; i++) {
30 sk_atomic_add(&base, addInfo->valueToAdd);
34 DEF_TEST(Atomic, reporter) {
36 SkThread* threads[SK_ARRAY_COUNT(gAdds)];
37 for (size_t i = 0; i < SK_ARRAY_COUNT(gAdds); i++) {
38 total += gAdds[i].valueToAdd * gAdds[i].timesToAdd;
41 for (size_t i = 0; i < SK_ARRAY_COUNT(gAdds); i++) {
42 threads[i] = new SkThread(addABunchOfTimes, &gAdds[i]);
43 threads[i]->setProcessorAffinity(gAdds[i].processorAffinity);
47 // Now end the threads
48 for (size_t i = 0; i < SK_ARRAY_COUNT(gAdds); i++) {
52 REPORTER_ASSERT(reporter, total == base);
53 // Ensure that the returned value from sk_atomic_add is correct.
54 int32_t valueToModify = 3;
55 const int32_t originalValue = valueToModify;
56 REPORTER_ASSERT(reporter, originalValue == sk_atomic_add(&valueToModify, 7));