Renaming cds/cxx11_atomic.h to cds/algo/atomic.h
[libcds.git] / cds / memory / michael / osalloc_stat.h
1 //$$CDS-header$$
2
3 #ifndef __CDS_MEMORY_MICHAEL_ALLOCATOR_OSALLOC_STAT_H
4 #define __CDS_MEMORY_MICHAEL_ALLOCATOR_OSALLOC_STAT_H
5
6 #include <cds/algo/atomic.h>
7
8 namespace cds { namespace memory { namespace michael {
9
10     /// Statistics for large  (allocated directly from %OS) block
11     struct os_allocated_atomic
12     {
13         ///@cond
14         atomics::atomic<size_t>              nAllocCount         ;   ///< Event count of large block allocation from %OS
15         atomics::atomic<size_t>              nFreeCount          ;   ///< Event count of large block deallocation to %OS
16         atomics::atomic<unsigned long long>  nBytesAllocated     ;   ///< Total size of allocated large blocks, in bytes
17         atomics::atomic<unsigned long long>  nBytesDeallocated   ;   ///< Total size of deallocated large blocks, in bytes
18
19         os_allocated_atomic()
20             : nAllocCount(0)
21             , nFreeCount(0)
22             , nBytesAllocated(0)
23             , nBytesDeallocated(0)
24         {}
25         ///@endcond
26
27         /// Adds \p nSize to nBytesAllocated counter
28         void incBytesAllocated( size_t nSize )
29         {
30             nAllocCount.fetch_add( 1, atomics::memory_order_relaxed);
31             nBytesAllocated.fetch_add( nSize, atomics::memory_order_relaxed );
32         }
33
34         /// Adds \p nSize to nBytesDeallocated counter
35         void incBytesDeallocated( size_t nSize )
36         {
37             nFreeCount.fetch_add( 1, atomics::memory_order_relaxed );
38             nBytesDeallocated.fetch_add( nSize, atomics::memory_order_relaxed );
39         }
40
41         /// Returns count of \p alloc and \p alloc_aligned function call (for large block allocated directly from %OS)
42         size_t allocCount() const
43         {
44             return nAllocCount.load(atomics::memory_order_relaxed);
45         }
46
47         /// Returns count of \p free and \p free_aligned function call (for large block allocated directly from %OS)
48         size_t freeCount() const
49         {
50             return nFreeCount.load(atomics::memory_order_relaxed);
51         }
52
53         /// Returns current value of nBytesAllocated counter
54         atomic64u_t allocatedBytes() const
55         {
56             return nBytesAllocated.load(atomics::memory_order_relaxed);
57         }
58
59         /// Returns current value of nBytesAllocated counter
60         atomic64u_t deallocatedBytes() const
61         {
62             return nBytesDeallocated.load(atomics::memory_order_relaxed);
63         }
64     };
65
66     /// Dummy statistics for large (allocated directly from %OS) block
67     /**
68         This class does not gather any statistics.
69         Class interface is the same as \ref os_allocated_atomic.
70     */
71     struct os_allocated_empty
72     {
73     //@cond
74         /// Adds \p nSize to nBytesAllocated counter
75         void incBytesAllocated( size_t nSize )
76         { CDS_UNUSED(nSize); }
77
78         /// Adds \p nSize to nBytesDeallocated counter
79         void incBytesDeallocated( size_t nSize )
80         { CDS_UNUSED(nSize); }
81
82         /// Returns count of \p alloc and \p alloc_aligned function call (for large block allocated directly from OS)
83         size_t allocCount() const
84         {
85             return 0;
86         }
87
88         /// Returns count of \p free and \p free_aligned function call (for large block allocated directly from OS)
89         size_t freeCount() const
90         {
91             return 0;
92         }
93
94         /// Returns current value of nBytesAllocated counter
95         atomic64u_t allocatedBytes() const
96         {
97             return 0;
98         }
99
100         /// Returns current value of nBytesAllocated counter
101         atomic64u_t deallocatedBytes() const
102         {
103             return 0;
104         }
105     //@endcond
106     };
107
108
109 }}} // namespace cds::memory::michael
110
111 #endif  /// __CDS_MEMORY_MICHAEL_ALLOCATOR_OSALLOC_STAT_H