All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
nonBlockDelete.h
Go to the documentation of this file.
1 /* nonBlockDelete.h
2  */
3 #ifndef OSL_NONBLOCKDELETE_H
4 #define OSL_NONBLOCKDELETE_H
5 
6 #include <boost/shared_ptr.hpp>
7 #include <boost/utility.hpp>
8 
9 #ifdef USE_BOOST_POOL_ALLOCATOR
10 # define DISABLE_NON_BLOCK_DELETE
11 #endif
12 
13 namespace osl
14 {
15  namespace misc
16  {
17  class NonBlockDelete : boost::noncopyable
18  {
19  public:
21  template <class T>
22  static void planDelete(T *ptr)
23  {
24  boost::shared_ptr<void> holder(ptr); // shared_ptr preserves T
25  resetAny(holder);
26  }
27 
31  template <class T>
32  static void reset(boost::shared_ptr<T>& ptr)
33  {
34 #ifndef DISABLE_NON_BLOCK_DELETE
35  boost::shared_ptr<void> holder;
36  holder = ptr;
37 #endif
38  ptr.reset();
39 #ifndef DISABLE_NON_BLOCK_DELETE
40  resetAny(holder);
41 #endif
42  }
43  static void resetAny(boost::shared_ptr<void>&);
44 
48  static void deleteAll();
49  static bool deleteOne();
50  static int waiting();
51  private:
52  static NonBlockDelete& instance();
53 
56  void push_back(boost::shared_ptr<void>&);
57 
58  class Queue;
59  boost::shared_ptr<Queue> queue;
60 
61  struct Runner;
62  friend struct Runner;
63  };
64 
65  }
67 }
68 
69 #endif /* OSL_NONBLOCKDELETE_H */
70 // ;;; Local Variables:
71 // ;;; mode:c++
72 // ;;; c-basic-offset:2
73 // ;;; coding:utf-8
74 // ;;; End: