Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
B
brpc
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
brpc
Commits
2cb180f3
Commit
2cb180f3
authored
Aug 16, 2018
by
Ge Jun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify ConstantConcurrencyLimiter
parent
7c65df38
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
24 deletions
+19
-24
constant_concurrency_limiter.cpp
src/brpc/policy/constant_concurrency_limiter.cpp
+11
-15
constant_concurrency_limiter.h
src/brpc/policy/constant_concurrency_limiter.h
+8
-9
No files found.
src/brpc/policy/constant_concurrency_limiter.cpp
View file @
2cb180f3
...
...
@@ -19,29 +19,25 @@
namespace
brpc
{
namespace
policy
{
bool
ConstantConcurrencyLimiter
::
OnRequested
()
{
const
int32_t
current_concurrency
=
_current_concurrency
.
fetch_add
(
1
,
butil
::
memory_order_relaxed
);
if
(
_max_concurrency
!=
0
&&
current_concurrency
>=
_max_concurrency
)
{
return
false
;
}
return
true
;
ConstantConcurrencyLimiter
::
ConstantConcurrencyLimiter
(
int
max_concurrency
)
:
_max_concurrency
(
max_concurrency
)
{
}
void
ConstantConcurrencyLimiter
::
OnResponded
(
int
error_code
,
int64_t
lat
ency
)
{
_current_concurrency
.
fetch_sub
(
1
,
butil
::
memory_order_relaxed
)
;
bool
ConstantConcurrencyLimiter
::
OnRequested
(
int
current_concurr
ency
)
{
return
current_concurrency
<=
_max_concurrency
;
}
int
ConstantConcurrencyLimiter
::
Expose
(
const
butil
::
StringPiece
&
prefix
)
{
return
0
;
void
ConstantConcurrencyLimiter
::
OnResponded
(
int
error_code
,
int64_t
latency
)
{
}
ConstantConcurrencyLimiter
*
ConstantConcurrencyLimiter
::
New
()
const
{
return
new
(
std
::
nothrow
)
ConstantConcurrencyLimiter
;
int
ConstantConcurrencyLimiter
::
MaxConcurrency
()
{
return
_max_concurrency
.
load
(
butil
::
memory_order_relaxed
)
;
}
void
ConstantConcurrencyLimiter
::
Destroy
()
{
delete
this
;
ConstantConcurrencyLimiter
*
ConstantConcurrencyLimiter
::
New
(
const
AdaptiveMaxConcurrency
&
amc
)
const
{
CHECK_EQ
(
amc
.
type
(),
AdaptiveMaxConcurrency
::
CONSTANT
());
return
new
ConstantConcurrencyLimiter
(
static_cast
<
int
>
(
amc
));
}
}
// namespace policy
...
...
src/brpc/policy/constant_concurrency_limiter.h
View file @
2cb180f3
...
...
@@ -24,19 +24,18 @@ namespace policy {
class
ConstantConcurrencyLimiter
:
public
ConcurrencyLimiter
{
public
:
ConstantConcurrencyLimiter
()
:
_current_concurrency
(
0
)
{}
~
ConstantConcurrencyLimiter
()
{}
bool
OnRequested
()
override
;
explicit
ConstantConcurrencyLimiter
(
int
max_concurrency
);
bool
OnRequested
(
int
current_concurrency
)
override
;
void
OnResponded
(
int
error_code
,
int64_t
latency_us
)
override
;
int
Expose
(
const
butil
::
StringPiece
&
prefix
)
override
;
ConstantConcurrencyLimiter
*
New
()
const
override
;
void
Destroy
()
override
;
int
MaxConcurrency
(
)
override
;
ConstantConcurrencyLimiter
*
New
(
const
AdaptiveMaxConcurrency
&
)
const
override
;
private
:
butil
::
atomic
<
int
32_t
>
_current
_concurrency
;
butil
::
atomic
<
int
>
_max
_concurrency
;
};
}
// namespace policy
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment