X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fgc-anchored.cpp;h=3f4cfc12dcf8cbe1a3022882495dbfe451f480f5;hb=03a65c733a473cd92d50132961d02c3910417f72;hp=02dff76d435b60f56525fdd11b1460f1ce75b547;hpb=6b15695578f07a3f72c4c9475c1a261a3021472a;p=inkscape.git diff --git a/src/gc-anchored.cpp b/src/gc-anchored.cpp index 02dff76d4..3f4cfc12d 100644 --- a/src/gc-anchored.cpp +++ b/src/gc-anchored.cpp @@ -9,12 +9,51 @@ * Released under GNU GPL, 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/share.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, + Util::ptr_shared name) + : RefCountEvent(name) + { + _addProperty("base", Util::format("%p", Core::base(const_cast(object)))); + _addProperty("pointer", Util::format("%p", object)); + _addProperty("class", Debug::demangle(typeid(*object).name())); + _addProperty("new-refcount", Util::format("%d", object->_anchored_refcount() + bias)); + } +}; + +class AnchorEvent : public BaseAnchorEvent { +public: + AnchorEvent(Anchored const *object) + : BaseAnchorEvent(object, 1, Util::share_static_string("gc-anchor")) + {} +}; + +class ReleaseEvent : public BaseAnchorEvent { +public: + ReleaseEvent(Anchored const *object) + : BaseAnchorEvent(object, -1, Util::share_static_string("gc-release")) + {} +}; + +} + Anchored::Anchor *Anchored::_new_anchor() const { return new Anchor(this); } @@ -23,6 +62,22 @@ 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); + if (!--_anchor->refcount) { + _free_anchor(_anchor); + _anchor = NULL; + } +} + } }