OpenSDN source code
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
flow_token.cc
Go to the documentation of this file.
1
#include "
flow_token.h
"
2
#include "
flow_proto.h
"
3
4
Token::Token
(
TokenPool
*pool) :
5
pool_(pool){
6
}
7
8
Token::~Token
() {
9
if
(
pool_
)
10
pool_
->
FreeToken
();
11
}
12
13
TokenPool::TokenPool
(
const
std::string &name,
Proto
*proto,
14
int
count) :
15
name_(name), max_tokens_(count), min_tokens_(count),
16
low_water_mark_((count * 10)/100), failures_(0), restarts_(0),
17
proto_(proto) {
18
token_count_
= count;
19
}
20
21
TokenPool::~TokenPool
() {
22
}
23
24
void
TokenPool::FreeToken
() {
25
int
val =
token_count_
.fetch_and_increment();
26
assert(val <=
max_tokens_
);
27
if
(val ==
low_water_mark_
) {
28
proto_
->
TokenAvailable
(
this
);
29
}
30
}
31
32
bool
TokenPool::TokenCheck
()
const
{
33
if
(
token_count_
> 0) {
34
return
true
;
35
}
36
37
failures_
++;
38
return
false
;
39
}
40
41
TokenPtr
TokenPool::GetToken
() {
42
int
val =
token_count_
.fetch_and_decrement();
43
if
(val <
min_tokens_
)
44
min_tokens_
= val;
45
return
TokenPtr
(
new
Token
(
this
));
46
}
47
48
TokenPtr
FlowTokenPool::GetToken
(
FlowEntry
*entry) {
49
int
val =
token_count_
.fetch_and_decrement();
50
if
(val <
min_tokens_
)
51
min_tokens_
= val;
52
return
TokenPtr
(
new
FlowToken
(
this
, entry));
53
}
TokenPool::Token
friend class Token
Definition:
flow_token.h:37
TokenPool::failures_
uint64_t failures_
Definition:
flow_token.h:47
TokenPool::TokenPool
TokenPool(const std::string &name, Proto *proto, int count)
Definition:
flow_token.cc:13
TokenPool::proto_
Proto * proto_
Definition:
flow_token.h:49
TokenPool::FreeToken
void FreeToken()
Definition:
flow_token.cc:24
FlowToken
Definition:
flow_token.h:61
FlowEntry
Definition:
flow_entry.h:460
TokenPool::max_tokens_
int max_tokens_
Definition:
flow_token.h:43
Proto
Definition:
controller/src/vnsw/agent/pkt/proto.h:15
flow_proto.h
flow_token.h
TokenPool::token_count_
tbb::atomic< int > token_count_
Definition:
flow_token.h:46
Token::pool_
TokenPool * pool_
Definition:
flow_token.h:21
TokenPool::low_water_mark_
int low_water_mark_
Definition:
flow_token.h:45
Token::Token
Token(TokenPool *pool)
Definition:
flow_token.cc:4
Proto::TokenAvailable
virtual void TokenAvailable(TokenPool *pool)
Definition:
controller/src/vnsw/agent/pkt/proto.h:37
TokenPool::GetToken
virtual TokenPtr GetToken()
Definition:
flow_token.cc:41
TokenPool::min_tokens_
int min_tokens_
Definition:
flow_token.h:44
TokenPool
Definition:
flow_token.h:25
TokenPtr
boost::shared_ptr< Token > TokenPtr
Definition:
flow_token.h:11
TokenPool::~TokenPool
virtual ~TokenPool()
Definition:
flow_token.cc:21
Token::~Token
virtual ~Token()
Definition:
flow_token.cc:8
TokenPool::TokenCheck
bool TokenCheck() const
Definition:
flow_token.cc:32
contrail
controller
src
vnsw
agent
pkt
flow_token.cc
Generated by
1.8.5