]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/mem_pool.h
Big backport from Enterprise
[bacula/bacula] / bacula / src / lib / mem_pool.h
index ee4dfbbbe61a4baa3e3d011d59cfa514d0bcc760..95172cb841f4b64f7d43813573b998f1b5bc8434 100644 (file)
@@ -1,28 +1,26 @@
 /*
- * Memory Pool prototypes
- *
- *  Kern Sibbald, MM
- *
- *   Version $Id$
- */
-/*
-   Copyright (C) 2000-2004 Kern Sibbald and John Walker
+   Bacula(R) - The Network Backup Solution
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of
-   the License, or (at your option) any later version.
+   Copyright (C) 2000-2017 Kern Sibbald
 
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-   General Public License for more details.
+   The original author of Bacula is Kern Sibbald, with contributions
+   from many others, a complete list can be found in the file AUTHORS.
 
-   You should have received a copy of the GNU General Public
-   License along with this program; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
-   MA 02111-1307, USA.
+   You may use this file and others of this release according to the
+   license defined in the LICENSE file, which includes the Affero General
+   Public License, v3.0 ("AGPLv3") and some additional permissions and
+   terms pursuant to its AGPLv3 Section 7.
 
+   This notice must be preserved when any source code is 
+   conveyed and/or propagated.
+
+   Bacula(R) is a registered trademark of Kern Sibbald.
+*/
+/*
+ * Memory Pool prototypes
+ *
+ *  Kern Sibbald, MM
+ *
  */
 
 #ifndef __MEM_POOL_H_
@@ -50,7 +48,6 @@ extern POOLMEM  *sm_check_pool_memory_size(const char *fname, int line, POOLMEM
 #define free_memory(x) sm_free_pool_memory(__FILE__, __LINE__, x)
 extern void sm_free_pool_memory(const char *fname, int line, POOLMEM *buf);
 
-
 #else
 
 extern POOLMEM *get_pool_memory(int pool);
@@ -63,9 +60,14 @@ extern void   free_pool_memory(POOLMEM *buf);
 
 #endif
 
+/* Macro to simplify free/reset pointers */
+#define free_and_null_pool_memory(a) do{if(a){free_pool_memory(a); (a)=NULL;}} while(0)
+
+extern void garbage_collect_memory_pool();
 extern void  close_memory_pool();
 extern void  print_memory_pool_stats();
 
+extern void garbage_collect_memory();
 
 
 #define PM_NOPOOL  0                  /* nonpooled memory */
@@ -73,7 +75,8 @@ extern void  print_memory_pool_stats();
 #define PM_FNAME   2                  /* file name buffer */
 #define PM_MESSAGE 3                  /* daemon message */
 #define PM_EMSG    4                  /* error message */
-#define PM_MAX     PM_EMSG            /* Number of types */
+#define PM_BSOCK   5                  /* BSOCK buffer */
+#define PM_MAX     PM_BSOCK           /* Number of types */
 
 class POOL_MEM {
    char *mem;
@@ -82,6 +85,7 @@ public:
    POOL_MEM(int pool) { mem = get_pool_memory(pool); *mem = 0; }
    ~POOL_MEM() { free_pool_memory(mem); mem = NULL; }
    char *c_str() const { return mem; }
+   POOLMEM *&addr() { return mem; }
    int size() const { return sizeof_pool_memory(mem); }
    char *check_size(int32_t size) {
       mem = check_pool_memory_size(mem, size);
@@ -93,14 +97,20 @@ public:
    int strcat(const char *str);
 };
 
-int pm_strcat (POOLMEM **pm, const char *str);
-int pm_strcat (POOLMEM *&pm, const char *str);
-int pm_strcat (POOL_MEM &pm, const char *str);
-int pm_strcat (POOLMEM *&pm, POOL_MEM &str);
-int pm_strcpy (POOLMEM **pm, const char *str);
-int pm_strcpy (POOLMEM *&pm, const char *str);
-int pm_strcpy (POOL_MEM &pm, const char *str);
-int pm_strcpy (POOLMEM *&pm, POOL_MEM &str);
-
+int pm_strcat(POOLMEM **pm, const char *str);
+int pm_strcat(POOLMEM *&pm, const char *str);
+int pm_strcat(POOL_MEM &pm, const char *str);
+int pm_strcat(POOLMEM *&pm, POOL_MEM &str);
+int pm_strcat(POOL_MEM &pm, POOL_MEM &str);
+
+int pm_strcpy(POOLMEM **pm, const char *str);
+int pm_strcpy(POOLMEM *&pm, const char *str);
+int pm_strcpy(POOL_MEM &pm, const char *str);
+int pm_strcpy(POOLMEM *&pm, POOL_MEM &str);
+
+int pm_memcpy(POOLMEM **pm, const char *data, int32_t n);
+int pm_memcpy(POOLMEM *&pm, const char *data, int32_t n);
+int pm_memcpy(POOL_MEM &pm, const char *data, int32_t n);
+int pm_memcpy(POOLMEM *&pm, POOL_MEM &data, int32_t n);
 
 #endif