Free Electron
Tracker.h
Go to the documentation of this file.
1 /* Copyright (C) 2003-2021 Free Electron Organization
2  Any use of this software requires a license. If a valid license
3  was not distributed with this file, visit freeelectron.org. */
4 
5 /** @file */
6 
7 #ifndef __core_Tracker_h__
8 #define __core_Tracker_h__
9 
10 namespace fe
11 {
12 
13 /**************************************************************************//**
14  @brief Watches the usage of reference counted objects
15 
16  @ingroup core
17 
18  Counted has debugging mechanisms that manipulate a Tracker
19  during validation. It can be printed using Counted::reportTracker().
20 
21  A major singleton (like Registry in the plugin mode) may
22  set up and maintain another Tracker automatically
23  (such as for Component) while in an appropiate debugging mode.
24 *//***************************************************************************/
25 class FE_DL_EXPORT Tracker: public ObjectSafe<Tracker>
26 {
27  public:
28  Tracker(String name): m_name(name) {}
29 virtual ~Tracker(void);
30 
31  void suppress(void *pPtr);
32 
33  void acquire(void *pPtr,String name,U32 newcount)
34  { change(FALSE,pPtr,name,newcount); }
35  void release(void *pPtr,String name,U32 newcount)
36  { change(TRUE,pPtr,name,newcount); }
37 
38  void addReference(void* pPtr,void* pReference,
39  String what)
40  { changeReference(FALSE,pPtr,pReference,what); }
41  void removeReference(void* pPtr,void* pReference)
42  { changeReference(TRUE,pPtr,pReference,
43  String()); }
44 
45  /** @brief Register a block of memory
46 
47  pPtr is the object as a common form,
48  such as Counted.
49  pT is the start of the actually allocated block. */
50  void registerRegion(void* pPtr,void* pT,U32 bytes,
51  String name);
52  void deregisterRegion(void* pPtr);
53 
54  /** @brief Generate a report of current
55  object usage */
56  String report(void) const;
57  U32 totalCount(void) const;
58 
59  private:
60 
61  class FE_DL_PUBLIC Track
62  {
63  public:
64  Track(void):
65  m_count(0),
66  m_base(0x0),
67  m_size(0),
68  m_suppress(false),
69  m_referencesFound(0) {}
70 
71  U32 m_count;
72  void* m_base;
73  U32 m_size;
74  BWORD m_suppress;
75  U32 m_referencesFound;
76  String m_name;
77  std::map<void*,String> m_references;
78  };
79 
80  void change(BWORD release,void *pPtr,
81  String name,U32 newcount);
82  void changeReference(BWORD remove,void* pPtr,
83  void* pReference,String what);
84  String reportAt(std::map<void*,Track>::const_iterator it,
85  std::map<void*,Track>::const_iterator
86  itRoot,U32 depth,BWORD& rCycled) const;
87 
88  std::map<void*,Track> m_trackMap;
89  String m_name;
90 };
91 
92 } /* namespace */
93 
94 #endif /* __core_Tracker_h__ */
Object level locking for thread safety.
Definition: Safe.h:216
kernel
Definition: namespace.dox:3
Watches the usage of reference counted objects.
Definition: Tracker.h:25
Automatically reference-counted string container.
Definition: String.h:128