source: XIOS/dev/dev_trunk_omp/src/filter/garbage_collector.hpp @ 1670

Last change on this file since 1670 was 1670, checked in by yushan, 5 years ago

MARK: branch merged with trunk @1663. Generate one static graph for each output file

File size: 2.1 KB
Line 
1#ifndef __XIOS_CGarbageCollector__
2#define __XIOS_CGarbageCollector__
3
4#include <map>
5#include <set>
6
7#include "date.hpp"
8
9namespace xios
10{
11  /*!
12   * Interface shared by all objects that might need to invalidate packets.
13   */
14  struct InvalidableObject
15  {
16    /*!
17     * Removes all pending packets which are older than the specified timestamp.
18     *
19     * \param timestamp the timestamp used for invalidation
20     */
21    void virtual invalidate(Time timestamp) = 0;
22
23    static std::map<StdString, int> *count_ptr;
24    #pragma omp threadprivate(count_ptr)
25 
26    static int count; //!< Counter used to identify a filter in case building workflow graph
27    #pragma omp threadprivate(count)
28   
29  }; // struct InvalidableObject
30
31  /*!
32   * A basic garbage collector which ensures no old packets linger in the filter graph.
33   */
34  class CGarbageCollector
35  {
36    public:
37      /*!
38       * Constructs a garbage collector.
39       */
40      CGarbageCollector()
41      { /* Nothing to do */ };
42
43      /*!
44       * Registers an object for a specified timestamp.
45       *
46       * \param object the object to register
47       * \param timestamp the timestamp for which the object is registered
48       */
49      void registerObject(InvalidableObject* object, Time timestamp);
50
51      /*!
52       * Removes a object previously registered for a specified timestamp.
53       *
54       * \param object the object to unregister
55       * \param timestamp the timestamp for which the object is unregistered
56       */
57      void unregisterObject(InvalidableObject* object, Time timestamp);
58
59      /*!
60       * Ensures all registered objects invalidate packets older than the specified timestamp.
61       *
62       * \param timestamp the timestamp used for invalidation
63       */
64      void invalidate(Time timestamp);
65
66    private:
67      CGarbageCollector(const CGarbageCollector&);
68      CGarbageCollector& operator=(const CGarbageCollector&);
69
70      std::map<Time, std::set<InvalidableObject*> > registeredObjects; //!< Currently registered objects
71  }; // class CGarbageCollector
72} // namespace xios
73
74#endif //__XIOS_CGarbageCollector__
Note: See TracBrowser for help on using the repository browser.