Marine Library  1.0
C++ library for Linux Networking Development
attr_stats.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016 Zhao DAI <daidodo@gmail.com>
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or any
7  * later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see accompanying file LICENSE.txt
16  * or <http://www.gnu.org/licenses/>.
17  */
18 
28 #ifndef DOZERG_ATTR_STATS_H_20130606
29 #define DOZERG_ATTR_STATS_H_20130606
30 
31 #include "impl/attr_stats_impl.hh"
32 
33 NS_SERVER_BEGIN
34 
63 #define ATTR_ADD(attr, val) \
64  do{ \
65  __UNUSED typedef NS_SERVER::NS_IMPL::__AttrDummy<attr> attr_must_be_constant; \
66  static uint64_t * __Attr = NULL; \
67  if(!__Attr){ \
68  __Attr = NS_SERVER::NS_IMPL::CAttrStats::Inst().attrAdd(attr, val); \
69  }else \
70  NS_SERVER::NS_IMPL::CAttrStats::attrAdd(__Attr, val); \
71  }while(0)
72 
79 inline bool ATTR_INIT(size_t capacity = 1000)
80 {
81  return NS_IMPL::CAttrStats::Inst().init(capacity);
82 }
83 
91 inline bool ATTR_ADD_SLOW(int attr, uint64_t val)
92 {
93  return (NULL != NS_IMPL::CAttrStats::Inst().attrAdd(attr, val));
94 }
95 
122 #define ATTR_SET(attr, val) \
123  do{ \
124  __UNUSED typedef NS_SERVER::NS_IMPL::__AttrDummy<attr> attr_must_be_constant; \
125  static uint64_t * __Attr = NULL; \
126  if(!__Attr){ \
127  __Attr = NS_SERVER::NS_IMPL::CAttrStats::Inst().attrSet(attr, val); \
128  }else \
129  NS_SERVER::NS_IMPL::CAttrStats::attrSet(__Attr, val); \
130  }while(0)
131 
145 #define ATTR_SET_EX(attr, val, old) \
146  do{ \
147  __UNUSED typedef NS_SERVER::NS_IMPL::__AttrDummy<attr> attr_must_be_constant; \
148  static uint64_t * __Attr = NULL; \
149  if(!__Attr){ \
150  __Attr = NS_SERVER::NS_IMPL::CAttrStats::Inst().attrSet(attr, val, old); \
151  }else \
152  NS_SERVER::NS_IMPL::CAttrStats::attrSet(__Attr, val, old); \
153  }while(0)
154 
163 inline bool ATTR_SET_SLOW(int attr, uint64_t val, uint64_t * old = NULL)
164 {
165  return (NULL != NS_IMPL::CAttrStats::Inst().attrSet(attr, val, old));
166 }
167 
177 template<class Op>
178 inline void ATTR_ITERATE(Op op)
179 {
180  return NS_IMPL::CAttrStats::Inst().iterate(op);
181 }
182 
183 NS_SERVER_END
184 
185 #endif
186 
bool ATTR_ADD_SLOW(int attr, uint64_t val)
Increase an attribute atomically.
Definition: attr_stats.hh:91
void ATTR_ITERATE(Op op)
Iterate and apply an operation to all attributes.
Definition: attr_stats.hh:178
bool ATTR_INIT(size_t capacity=1000)
Initialize statistics APIs.
Definition: attr_stats.hh:79
bool ATTR_SET_SLOW(int attr, uint64_t val, uint64_t *old=NULL)
Get an attribute and then modify it atomically.
Definition: attr_stats.hh:163