From cca66b9ec4e494c1d919bff0f71a820d8afab1fa Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 20:24:48 +0200 Subject: Adding upstream version 1.2.2. Signed-off-by: Daniel Baumann --- src/gc-anchored.cpp | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 src/gc-anchored.cpp (limited to 'src/gc-anchored.cpp') diff --git a/src/gc-anchored.cpp b/src/gc-anchored.cpp new file mode 100644 index 0000000..12eaa83 --- /dev/null +++ b/src/gc-anchored.cpp @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Inkscape::GC::Anchored - base class for anchored GC-managed objects + * + * Authors: + * MenTaLguY + * + * Copyright (C) 2004 MenTaLguY + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include +#include "gc-anchored.h" +#include "debug/event-tracker.h" +#include "debug/simple-event.h" +#include "debug/demangle.h" +#include "util/format.h" + +namespace Inkscape { + +namespace GC { + +namespace { + +typedef Debug::SimpleEvent RefCountEvent; + +class BaseAnchorEvent : public RefCountEvent { +public: + BaseAnchorEvent(Anchored const *object, int bias, + char const *name) + : RefCountEvent(name) + { + _addProperty("base", Util::format("%p", Core::base(const_cast(object))).pointer()); + _addProperty("pointer", Util::format("%p", object).pointer()); + _addProperty("class", Debug::demangle(typeid(*object).name())); + _addProperty("new-refcount", object->_anchored_refcount() + bias); + } +}; + +class AnchorEvent : public BaseAnchorEvent { +public: + AnchorEvent(Anchored const *object) + : BaseAnchorEvent(object, 1, "gc-anchor") + {} +}; + +class ReleaseEvent : public BaseAnchorEvent { +public: + ReleaseEvent(Anchored const *object) + : BaseAnchorEvent(object, -1, "gc-release") + {} +}; + +} + +Anchored::Anchor *Anchored::_new_anchor() const { + return new Anchor(this); +} + +void Anchored::_free_anchor(Anchored::Anchor *anchor) const { + delete anchor; +} + +void Anchored::anchor() const { + Debug::EventTracker tracker(this); + if (!_anchor) { + _anchor = _new_anchor(); + } + _anchor->refcount++; +} + +void Anchored::release() const { + Debug::EventTracker tracker(this); + g_return_if_fail(_anchor); + if (!--_anchor->refcount) { + _free_anchor(_anchor); + _anchor = nullptr; + } +} + +} + +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : -- cgit v1.2.3