MADNESS  version 0.9
deferred_cleanup.h
Go to the documentation of this file.
1 /*
2  This file is part of MADNESS.
3 
4  Copyright (C) 2007,2010 Oak Ridge National Laboratory
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10 
11  This program is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with this program; if not, write to the Free Software
18  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 
20  For more information please contact:
21 
22  Robert J. Harrison
23  Oak Ridge National Laboratory
24  One Bethel Valley Road
25  P.O. Box 2008, MS-6367
26 
27  email: harrisonrj@ornl.gov
28  tel: 865-241-3937
29  fax: 865-572-0680
30 
31 
32  $Id$
33 */
34 
35 #ifndef MADNESS_WORLD_DEFERRED_CLEANUP_H__INCLUDED
36 #define MADNESS_WORLD_DEFERRED_CLEANUP_H__INCLUDED
37 
39 #include <madness/world/worldmutex.h> // For Mutex
40 #include <list>
41 
42 namespace madness {
43 
44  // Forward declarations
45  template <typename, typename>
47  class World;
48 
49  namespace detail {
50 
52 
58  public:
60 
61  private:
62  typedef std::list<void_ptr> void_ptr_list;
63 
64  RecursiveMutex mutex_;
65  void_ptr_list deferred_;
66  bool destroy_;
67 
70  // not allowed
72  DeferredCleanup& operator=(const DeferredCleanup&);
73 
74  template <typename, typename>
75  friend class ::madness::DeferredDeleter;
76 
78 
81  static std::shared_ptr<DeferredCleanup> get_deferred_cleanup(const World& w);
82 
83  public:
85  DeferredCleanup() : mutex_(), deferred_(), destroy_(false) { }
86 
88 
91  void destroy(bool mode);
92 
94 
97  bool destroy() const;
98 
100 
104  void add(const void_ptr& obj);
105 
107  void do_cleanup();
108  }; // class DeferredCleanup
109 
110  } // namespace detail
111 } // namespace madness
112 
113 #endif // MADNESS_WORLD_DEFERRED_CLEANUP_H__INCLUDED
Deferred deleter for smart pointers.
Definition: deferred_cleanup.h:46
std::shared_ptr< void > void_ptr
input pointer type
Definition: deferred_cleanup.h:59
Recursive mutex using pthread mutex operations.
Definition: worldmutex.h:140
Deferred cleanup of shared_ptr's.
Definition: deferred_cleanup.h:57
DeferredCleanup()
Construct a deferred deleter object.
Definition: deferred_cleanup.h:85
Implements Mutex, MutexFair, Spinlock, ConditionVariable.
A parallel world with full functionality wrapping an MPI communicator.
Definition: worldfwd.h:416
void add(const void_ptr &obj)
Adds item to cleanup list.
Definition: deferred_cleanup.cc:54
bool destroy() const
Get the current destruction mode mode.
Definition: deferred_cleanup.cc:47
void do_cleanup()
Deletes/frees any pointers that are in the list.
Definition: deferred_cleanup.cc:62
Holds machinery to set up Functions/FuncImpls using various Factories and Interfaces.
Definition: chem/atomutil.cc:45