skia2/tests/OncePtrTest.cpp
mtklein 59c12e3f00 remove non-static uses of SkOncePtr
Still slowly working through all the SK_DECLARE_STATIC_FOO macros.

SkOncePtr is complicating things by having SkOncePtr delete its pointer
and SkBaseOncePtr not.  Simplify things by removing SkOncePtr, leaving
only the leaky SkBaseOncePtr.

We replace SkOncePtr<T> instead with SkOnce and T.  In most cases this
did not need to be a pointer, and in some cases here we're even saving
a few bytes by replacing SkOncePtr<T> with SkOnce and a T.

The dependency map of SK_DECLARE_STATIC_FOO is:
  SkBaseMutex -> SkBaseSemaphore -> SkBaseOncePtr

They're intertwined enough that I think I've got to do all three in one
next CL.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1939503002

Review-Url: https://codereview.chromium.org/1939503002
2016-05-02 07:19:41 -07:00

27 lines
578 B
C++

/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "Test.h"
#include "SkOncePtr.h"
#include "SkTaskGroup.h"
SK_DECLARE_STATIC_ONCE_PTR(int, once);
DEF_TEST(OncePtr, r) {
static SkAtomic<int> calls(0);
auto create = [&] {
calls.fetch_add(1);
return new int(5);
};
SkTaskGroup().batch(sk_num_cores()*4, [&](size_t) {
int* n = once.get(create);
REPORTER_ASSERT(r, *n == 5);
});
REPORTER_ASSERT(r, calls.load() == 1);
}