Utils/Daemon: Add warning when the scheduler has registered events at a fork()
[senf.git] / Packets / PacketImpl.cc
index ebf720c..5b5e12f 100644 (file)
@@ -1,8 +1,8 @@
 // $Id$
 //
-// Copyright (C) 2007 
-// Fraunhofer Institute for Open Communication Systems (FOKUS) 
-// Competence Center NETwork research (NET), St. Augustin, GERMANY 
+// Copyright (C) 2007
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
 //     Stefan Bund <g0dil@berlios.de>
 //
 // This program is free software; you can redistribute it and/or modify
 #define prefix_
 ///////////////////////////////cc.p////////////////////////////////////////
 
+unsigned senf::detail::AnnotationIndexerBase::maxAnnotations (0);
+
 ///////////////////////////////////////////////////////////////////////////
 // senf::detail::PacketImpl
 
+prefix_ senf::detail::PacketImpl::~PacketImpl()
+{
+    // We increment refcount_ to ensure, release() won't call delete again
+    ++refcount_;
+    eraseInterpreters(interpreters_.begin(), interpreters_.end());
+    Annotations::const_iterator  i (annotations_.begin());
+    Annotations::const_iterator const i_end (annotations_.end());
+    std::vector<bool>::iterator small (AnnotationIndexerBase::small().begin());
+    for (; i != i_end; ++i, ++small)
+        if (! *small && *i)
+            delete *i;
+}
+
+// This function has a problem being inlined. Somehow, often when calling this, the size of the 
+// resulting inlined code would be huge. Need to further debug this.
+
+prefix_ void senf::detail::PacketImpl::release(refcount_t n)
+{
+    SENF_ASSERT(refcount_ >= n);
+    // uah ... we need to be extremely careful here. If refcount_ is n, we want to commit suicide,
+    // however the destructor will remove all PacketInterpreters from the list and will thereby
+    // decrement refcount -> only decrenebt refcount_ when *not* caling delete
+    if (refcount_ == n)
+        delete this;
+    else
+        refcount_ -= n;
+}
+
 // interpreter chain
 
 prefix_ void senf::detail::PacketImpl::appendInterpreter(PacketInterpreterBase * p)