cc1229c9d5
This reverts commit 33e00db73d
.
BUG=skia:
TBR=
NOTREECHECKS=True
FAILED: /b/build/goma/gomacc ../../third_party/llvm-build/Release+Asserts/bin/clang++ -MMD -MF obj/components/user_manager/user_manager_test_support.fake_user_manager.o.d -DV8_DEPRECATION_WARNINGS -DCLD_VERSION=2 -D_FILE_OFFSET_BITS=64 -DCHROMIUM_BUILD -DCR_CLANG_REVISION=242792-1 -DCOMPONENT_BUILD -DUI_COMPOSITOR_IMAGE_TRANSPORT -DUSE_AURA=1 -DUSE_ASH=1 -DUSE_PANGO=1 -DUSE_CAIRO=1 -DUSE_DEFAULT_RENDER_THEME=1 -DUSE_LIBJPEG_TURBO=1 -DUSE_X11=1 -DIMAGE_LOADER_EXTENSION=1 -DENABLE_WEBRTC=1 -DENABLE_MEDIA_ROUTER=1 -DUSE_PROPRIETARY_CODECS -DENABLE_PEPPER_CDMS -DENABLE_CONFIGURATION_POLICY -DENABLE_NOTIFICATIONS -DENABLE_HIDPI=1 -DENABLE_TOPCHROME_MD=1 -DUSE_UDEV -DDONT_EMBED_BUILD_METADATA -DDCHECK_ALWAYS_ON=1 -DFIELDTRIAL_TESTING_ENABLED -DENABLE_TASK_MANAGER=1 -DENABLE_EXTENSIONS=1 -DENABLE_PLUGINS=1 -DENABLE_SESSION_SERVICE=1 -DENABLE_THEMES=1 -DENABLE_AUTOFILL_DIALOG=1 -DENABLE_BACKGROUND=1 -DENABLE_GOOGLE_NOW=1 -DENABLE_PRINTING=1 -DENABLE_PRINT_PREVIEW=1 -DENABLE_SPELLCHECK=1 -DENABLE_CAPTIVE_PORTAL_DETECTION=1 -DENABLE_APP_LIST=1 -DENABLE_SUPERVISED_USERS=1 -DENABLE_MDNS=1 -DENABLE_SERVICE_DISCOVERY=1 -DV8_USE_EXTERNAL_STARTUP_DATA -DFULL_SAFE_BROWSING -DSAFE_BROWSING_CSD -DSAFE_BROWSING_DB_LOCAL -DSAFE_BROWSING_SERVICE -DGTEST_HAS_POSIX_RE=0 -DGTEST_LANG_CXX11=0 -DUNIT_TEST -DGTEST_HAS_RTTI=0 -DUSE_LIBPCI=1 -DUSE_OPENSSL=1 -DUSE_GLIB=1 -DUSE_NSS_CERTS=1 -DOS_CHROMEOS=1 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -DDYNAMIC_ANNOTATIONS_ENABLED=1 -DWTF_USE_DYNAMIC_ANNOTATIONS=1 -D_DEBUG -D_GLIBCXX_DEBUG=1 -Igen -I../.. -I../../skia/config -I../../testing/gmock/include -I../../testing/gtest/include -Werror -pthread -fno-strict-aliasing -Wall -Wno-unused-parameter -Wno-missing-field-initializers -fvisibility=hidden -pipe -fPIC -Wno-reserved-user-defined-literal -Xclang -load -Xclang /b/build/slave/linux_chromeos/build/src/third_party/llvm-build/Release+Asserts/lib/libFindBadConstructs.so -Xclang -add-plugin -Xclang find-bad-constructs -Xclang -plugin-arg-find-bad-constructs -Xclang check-templates -fcolor-diagnostics -B/b/build/slave/linux_chromeos/build/src/third_party/binutils/Linux_x64/Release/bin -Wheader-hygiene -Wno-char-subscripts -Wno-unneeded-internal-declaration -Wno-covered-switch-default -Wstring-conversion -Wno-c++11-narrowing -Wno-deprecated-register -Wno-inconsistent-missing-override -Wno-shift-negative-value -pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -m64 -march=x86-64 -O0 -g -funwind-tables -gsplit-dwarf -Wno-undefined-bool-conversion -Wno-tautological-undefined-compare -g0 -fno-exceptions -fno-rtti -fno-threadsafe-statics -fvisibility-inlines-hidden -Wsign-compare -std=gnu++11 -c ../../components/user_manager/fake_user_manager.cc -o obj/components/user_manager/user_manager_test_support.fake_user_manager.o
In file included from ../../components/user_manager/fake_user_manager.cc:5:
In file included from ../../components/user_manager/fake_user_manager.h:12:
In file included from ../../components/user_manager/user.h:14:
In file included from ../../components/user_manager/user_image/user_image.h:12:
In file included from ../../ui/gfx/image/image_skia.h:15:
In file included from ../../ui/gfx/image/image_skia_rep.h:8:
In file included from ../../third_party/skia/include/core/SkBitmap.h:11:
In file included from ../../third_party/skia/include/core/SkColor.h:11:
In file included from ../../third_party/skia/include/core/SkScalar.h:12:
../../third_party/skia/include/core/../private/SkFloatingPoint.h:13:10: fatal error: 'SkTypes.h' file not found
#include "SkTypes.h"
ninja -w dupbuild=err -C /b/build/slave/linux_chromeos/build/src/out/Debug accessibility_unittests accessibility_unittests_run app_list_unittests app_list_unittests_run app_shell_unittests app_shell_unittests_run ash_unittests ash_unittests_run aura_builder aura_unittests aura_unittests_run base_unittests base_unittests_run browser_tests browser_tests_run cacheinvalidation_unittests cacheinvalidation_unittests_run chromeos_unittests chromeos_unittests_run components_unittests components_unittests_run compositor_unittests compositor_unittests_run content_browsertests content_browsertests_run content_unittests content_unittests_run crypto_unittests crypto_unittests_run dbus_unittests device_unittests device_unittests_run display_unittests display_unittests_run events_unittests events_unittests_run extensions_browsertests extensions_browsertests_run extensions_unittests extensions_unittests_run gcm_unit_tests gcm_unit_tests_run gfx_unittests gfx_unittests_run google_apis_unittests google_apis_unittests_run gpu_unittests gpu_unittests_run interactive_ui_tests interactive_ui_tests_run ipc_tests ipc_tests_run jingle_unittests jingle_unittests_run media_unittests media_unittests_run message_center_unittests message_center_unittests_run midi_unittests midi_unittests_run nacl_helper_nonsfi_unittests nacl_loader_unittests nacl_loader_unittests_run net_unittests net_unittests_run ppapi_unittests printing_unittests printing_unittests_run remoting_unittests remoting_unittests_run sandbox_linux_unittests sandbox_linux_unittests_run skia_unittests skia_unittests_run sql_unittests sql_unittests_run sync_unit_tests sync_unit_tests_run ui_base_unittests ui_base_unittests_run ui_chromeos_unittests ui_touch_selection_unittests ui_touch_selection_unittests_run unit_tests unit_tests_run url_unittests url_unittests_run views_unittests wm_unittests wm_unittests_run -j50
ninja: Entering directory `/b/build/slave/linux_chromeos/build/src/out/Debug'
Review URL: https://codereview.chromium.org/1288863002
160 lines
5.6 KiB
C++
160 lines
5.6 KiB
C++
/*
|
|
* Copyright 2012 Google Inc.
|
|
*
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*/
|
|
|
|
#ifndef SkWeakRefCnt_DEFINED
|
|
#define SkWeakRefCnt_DEFINED
|
|
|
|
#include "SkRefCnt.h"
|
|
#include "SkAtomics.h"
|
|
|
|
/** \class SkWeakRefCnt
|
|
|
|
SkWeakRefCnt is the base class for objects that may be shared by multiple
|
|
objects. When an existing strong owner wants to share a reference, it calls
|
|
ref(). When a strong owner wants to release its reference, it calls
|
|
unref(). When the shared object's strong reference count goes to zero as
|
|
the result of an unref() call, its (virtual) weak_dispose method is called.
|
|
It is an error for the destructor to be called explicitly (or via the
|
|
object going out of scope on the stack or calling delete) if
|
|
getRefCnt() > 1.
|
|
|
|
In addition to strong ownership, an owner may instead obtain a weak
|
|
reference by calling weak_ref(). A call to weak_ref() must be balanced by a
|
|
call to weak_unref(). To obtain a strong reference from a weak reference,
|
|
call try_ref(). If try_ref() returns true, the owner's pointer is now also
|
|
a strong reference on which unref() must be called. Note that this does not
|
|
affect the original weak reference, weak_unref() must still be called. When
|
|
the weak reference count goes to zero, the object is deleted. While the
|
|
weak reference count is positive and the strong reference count is zero the
|
|
object still exists, but will be in the disposed state. It is up to the
|
|
object to define what this means.
|
|
|
|
Note that a strong reference implicitly implies a weak reference. As a
|
|
result, it is allowable for the owner of a strong ref to call try_ref().
|
|
This will have the same effect as calling ref(), but may be more expensive.
|
|
|
|
Example:
|
|
|
|
SkWeakRefCnt myRef = strongRef.weak_ref();
|
|
... // strongRef.unref() may or may not be called
|
|
if (myRef.try_ref()) {
|
|
... // use myRef
|
|
myRef.unref();
|
|
} else {
|
|
// myRef is in the disposed state
|
|
}
|
|
myRef.weak_unref();
|
|
*/
|
|
class SK_API SkWeakRefCnt : public SkRefCnt {
|
|
public:
|
|
/** Default construct, initializing the reference counts to 1.
|
|
The strong references collectively hold one weak reference. When the
|
|
strong reference count goes to zero, the collectively held weak
|
|
reference is released.
|
|
*/
|
|
SkWeakRefCnt() : SkRefCnt(), fWeakCnt(1) {}
|
|
|
|
/** Destruct, asserting that the weak reference count is 1.
|
|
*/
|
|
virtual ~SkWeakRefCnt() {
|
|
#ifdef SK_DEBUG
|
|
SkASSERT(fWeakCnt == 1);
|
|
fWeakCnt = 0;
|
|
#endif
|
|
}
|
|
|
|
/** Return the weak reference count.
|
|
*/
|
|
int32_t getWeakCnt() const { return fWeakCnt; }
|
|
|
|
#ifdef SK_DEBUG
|
|
void validate() const {
|
|
this->INHERITED::validate();
|
|
SkASSERT(fWeakCnt > 0);
|
|
}
|
|
#endif
|
|
|
|
/** Creates a strong reference from a weak reference, if possible. The
|
|
caller must already be an owner. If try_ref() returns true the owner
|
|
is in posession of an additional strong reference. Both the original
|
|
reference and new reference must be properly unreferenced. If try_ref()
|
|
returns false, no strong reference could be created and the owner's
|
|
reference is in the same state as before the call.
|
|
*/
|
|
bool SK_WARN_UNUSED_RESULT try_ref() const {
|
|
if (sk_atomic_conditional_inc(&fRefCnt) != 0) {
|
|
// Acquire barrier (L/SL), if not provided above.
|
|
// Prevents subsequent code from happening before the increment.
|
|
sk_membar_acquire__after_atomic_conditional_inc();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/** Increment the weak reference count. Must be balanced by a call to
|
|
weak_unref().
|
|
*/
|
|
void weak_ref() const {
|
|
SkASSERT(fRefCnt > 0);
|
|
SkASSERT(fWeakCnt > 0);
|
|
sk_atomic_inc(&fWeakCnt); // No barrier required.
|
|
}
|
|
|
|
/** Decrement the weak reference count. If the weak reference count is 1
|
|
before the decrement, then call delete on the object. Note that if this
|
|
is the case, then the object needs to have been allocated via new, and
|
|
not on the stack.
|
|
*/
|
|
void weak_unref() const {
|
|
SkASSERT(fWeakCnt > 0);
|
|
// Release barrier (SL/S), if not provided below.
|
|
if (sk_atomic_dec(&fWeakCnt) == 1) {
|
|
// Acquire barrier (L/SL), if not provided above.
|
|
// Prevents code in destructor from happening before the decrement.
|
|
sk_membar_acquire__after_atomic_dec();
|
|
#ifdef SK_DEBUG
|
|
// so our destructor won't complain
|
|
fWeakCnt = 1;
|
|
#endif
|
|
this->INHERITED::internal_dispose();
|
|
}
|
|
}
|
|
|
|
/** Returns true if there are no strong references to the object. When this
|
|
is the case all future calls to try_ref() will return false.
|
|
*/
|
|
bool weak_expired() const {
|
|
return fRefCnt == 0;
|
|
}
|
|
|
|
protected:
|
|
/** Called when the strong reference count goes to zero. This allows the
|
|
object to free any resources it may be holding. Weak references may
|
|
still exist and their level of allowed access to the object is defined
|
|
by the object's class.
|
|
*/
|
|
virtual void weak_dispose() const {
|
|
}
|
|
|
|
private:
|
|
/** Called when the strong reference count goes to zero. Calls weak_dispose
|
|
on the object and releases the implicit weak reference held
|
|
collectively by the strong references.
|
|
*/
|
|
void internal_dispose() const override {
|
|
weak_dispose();
|
|
weak_unref();
|
|
}
|
|
|
|
/* Invariant: fWeakCnt = #weak + (fRefCnt > 0 ? 1 : 0) */
|
|
mutable int32_t fWeakCnt;
|
|
|
|
typedef SkRefCnt INHERITED;
|
|
};
|
|
|
|
#endif
|