Disk ARchive  2.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
special_alloc.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21 // $Id: special_alloc.hpp,v 1.11 2011/01/09 17:25:58 edrusb Rel $
22 //
23 /*********************************************************************/
24 
35 
36 #ifndef SPECIAL_ALLOC_HPP
37 #define SPECIAL_ALLOC_HPP
38 
39 #include "../my_config.h"
40 
41 #ifdef LIBDAR_SPECIAL_ALLOC
42 
43 extern "C"
44 {
45 #if HAVE_STDDEF_H
46 #include <stddef.h>
47 #else
48 #if HAVE_STDLIB_H
49 #include <stdlib.h>
50 #endif
51 #endif
52 } // end extern "C"
53 
56 
57 #define USE_SPECIAL_ALLOC(BASE_TYPE) \
58  void *operator new(size_t taille) { return special_alloc_new(taille); }; \
59  void *operator new(size_t taille, BASE_TYPE * & place) { return (void *) place; }; \
60  void *operator new(size_t taille, void * & place) { return place; }; \
61  void operator delete(void *ptr) { special_alloc_delete(ptr); }
62 
63 namespace libdar
64 {
65  // this following call is to be used in a
66  // multi-thread environment and is called from
67  // libdar global initialization function
68  // this makes the libdar thread-safe if POSIX mutex
69  // are available
70  extern void special_alloc_init_for_thread_safe();
71 
72  extern void *special_alloc_new(size_t taille);
73  extern void special_alloc_delete(void *ptr);
74 
75 } // end of namespace
76 
77 #endif
78 
80 
81 #endif
82