]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
BEE Backport bacula/src/lib/dlist.h
authorEric Bollengier <eric@baculasystems.com>
Thu, 23 Apr 2020 13:50:52 +0000 (15:50 +0200)
committerEric Bollengier <eric@baculasystems.com>
Thu, 29 Apr 2021 08:44:16 +0000 (10:44 +0200)
This commit is the result of the squash of the following main commits:

Author: Eric Bollengier <eric@baculasystems.com>
Date:   Thu Feb 21 13:16:04 2019 +0100

    Allow to specify a custom delete handler in dlist

bacula/src/lib/dlist.h

index 73a84a77d211556b7882bf7a06fbc64d862f59b6..02cfd732fb82d3f0e5e8a904f605311bf40e0179 100644 (file)
@@ -57,11 +57,13 @@ struct dlink {
    void *prev;
 };
 
+
 class dlist : public SMARTALLOC {
    void *head;
    void *tail;
    int16_t loffset;
    uint32_t num_items;
+   void  (*free_method)(void *);
 public:
    dlist(void *item, dlink *link);
    dlist(void);
@@ -88,6 +90,7 @@ public:
    void destroy();
    void *first() const;
    void *last() const;
+   void set_delete(void (*fun)(void *));
 };
 
 
@@ -98,6 +101,7 @@ public:
  */
 inline void dlist::init(void *item, dlink *link)
 {
+   free_method = NULL;
    head = tail = NULL;
    loffset = (int)((char *)link - (char *)item);
    if (loffset < 0 || loffset > 5000) {
@@ -108,6 +112,7 @@ inline void dlist::init(void *item, dlink *link)
 
 inline void dlist::init()
 {
+   free_method = NULL;
    head = tail = NULL;
    loffset = 0;
    num_items = 0;
@@ -128,7 +133,7 @@ inline dlist::dlist(void *item, dlink *link)
 }
 
 /* Constructor with link at head of item */
-inline dlist::dlist(void) : head(0), tail(0), loffset(0), num_items(0)
+inline dlist::dlist(void) : head(0), tail(0), loffset(0), num_items(0), free_method(NULL)
 {
 }
 
@@ -182,6 +187,11 @@ inline void * dlist::last() const
    return tail;
 }
 
+inline void dlist::set_delete(void (*fun)(void *))
+{
+   free_method = fun;
+}
+
 /*
  * C string helper routines for dlist
  *   The string (char *) is kept in the node