diff options
author | mtklein <mtklein@google.com> | 2015-09-09 07:10:42 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-09-09 07:10:42 -0700 |
commit | 2ac6793efc9b33f6104f9c39810bee5714bdc208 (patch) | |
tree | 9d7e8e1e89d3fae55e7f6eabc9139fa28989d561 /tests | |
parent | 62fb1ba1786863e545c89839b5706ad5151cec15 (diff) |
Revert of Port uses of SkLazyPtr to SkOncePtr. (patchset #7 id:110001 of https://codereview.chromium.org/1322933005/ )
Reason for revert:
Breaks Chrome roll.
obj/skia/ext/skia_chrome.skia_memory_dump_provider.o
does not have -I include/private on its include path, but transitively includes SkMessageBus.h.
Original issue's description:
> Port uses of SkLazyPtr to SkOncePtr.
>
> This gives SkOncePtr a non-trivial destructor that uses std::default_delete
> by default. This is overrideable, as seen in SkColorTable.
>
> SK_DECLARE_STATIC_ONCE_PTR still just leaves its pointers hanging at EOP.
>
> BUG=skia:
>
> No public API changes.
> TBR=reed@google.com
>
> Committed: https://skia.googlesource.com/skia/+/a1254acdb344174e761f5061c820559dab64a74c
TBR=herb@google.com,mtklein@chromium.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=skia:
Review URL: https://codereview.chromium.org/1334523002
Diffstat (limited to 'tests')
-rw-r--r-- | tests/LazyPtrTest.cpp | 70 | ||||
-rw-r--r-- | tests/OncePtrTest.cpp | 2 |
2 files changed, 72 insertions, 0 deletions
diff --git a/tests/LazyPtrTest.cpp b/tests/LazyPtrTest.cpp new file mode 100644 index 0000000000..c6ffd72e25 --- /dev/null +++ b/tests/LazyPtrTest.cpp @@ -0,0 +1,70 @@ +/* + * Copyright 2014 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 "SkLazyPtr.h" +#include "SkRunnable.h" +#include "SkTaskGroup.h" + +namespace { + +struct CreateIntFromFloat { + CreateIntFromFloat(float val) : fVal(val) {} + int* operator()() const { return new int((int)fVal); } + float fVal; +}; + +// As a template argument this must have external linkage. +void custom_destroy(int* ptr) { *ptr = 99; } + +} // namespace + +DEF_TEST(LazyPtr, r) { + // Basic usage: calls new int. + SkLazyPtr<int> lazy; + int* ptr = lazy.get(); + REPORTER_ASSERT(r, ptr); + REPORTER_ASSERT(r, lazy.get() == ptr); + + // Advanced usage: calls a functor. + SkLazyPtr<int> lazyFunctor; + int* six = lazyFunctor.get(CreateIntFromFloat(6.4f)); + REPORTER_ASSERT(r, six); + REPORTER_ASSERT(r, 6 == *six); + + // Just makes sure this is safe. + SkLazyPtr<double> neverRead; + + // SkLazyPtr supports custom destroy methods. + { + SkLazyPtr<int, custom_destroy> customDestroy; + ptr = customDestroy.get(); + // custom_destroy called here. + } + REPORTER_ASSERT(r, ptr); + REPORTER_ASSERT(r, 99 == *ptr); + // Since custom_destroy didn't actually delete ptr, we do now. + delete ptr; +} + +DEF_TEST(LazyPtr_Threaded, r) { + static const int kRacers = 321; + + // Race to intialize the pointer by calling .get(). + SkLazyPtr<int> lazy; + int* seen[kRacers]; + + sk_parallel_for(kRacers, [&](int i) { + seen[i] = lazy.get(); + }); + + // lazy.get() should return the same pointer to all threads. + for (int i = 1; i < kRacers; i++) { + REPORTER_ASSERT(r, seen[i] != nullptr); + REPORTER_ASSERT(r, seen[i] == seen[0]); + } +} diff --git a/tests/OncePtrTest.cpp b/tests/OncePtrTest.cpp index b1e4e5d1ae..1b348dfd2d 100644 --- a/tests/OncePtrTest.cpp +++ b/tests/OncePtrTest.cpp @@ -28,6 +28,8 @@ DEF_TEST(OncePtr, r) { REPORTER_ASSERT(r, *n == 5); }); REPORTER_ASSERT(r, calls.load() == 1); + + delete (int*)once; } /* TODO(mtklein): next CL |