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 @@
...
@@ -19,29 +19,25 @@
namespace
brpc
{
namespace
brpc
{
namespace
policy
{
namespace
policy
{
bool
ConstantConcurrencyLimiter
::
OnRequested
()
{
ConstantConcurrencyLimiter
::
ConstantConcurrencyLimiter
(
int
max_concurrency
)
const
int32_t
current_concurrency
=
:
_max_concurrency
(
max_concurrency
)
{
_current_concurrency
.
fetch_add
(
1
,
butil
::
memory_order_relaxed
);
if
(
_max_concurrency
!=
0
&&
current_concurrency
>=
_max_concurrency
)
{
return
false
;
}
return
true
;
}
}
void
ConstantConcurrencyLimiter
::
OnResponded
(
int
error_code
,
int64_t
lat
ency
)
{
bool
ConstantConcurrencyLimiter
::
OnRequested
(
int
current_concurr
ency
)
{
_current_concurrency
.
fetch_sub
(
1
,
butil
::
memory_order_relaxed
)
;
return
current_concurrency
<=
_max_concurrency
;
}
}
int
ConstantConcurrencyLimiter
::
Expose
(
const
butil
::
StringPiece
&
prefix
)
{
void
ConstantConcurrencyLimiter
::
OnResponded
(
int
error_code
,
int64_t
latency
)
{
return
0
;
}
}
ConstantConcurrencyLimiter
*
ConstantConcurrencyLimiter
::
New
()
const
{
int
ConstantConcurrencyLimiter
::
MaxConcurrency
()
{
return
new
(
std
::
nothrow
)
ConstantConcurrencyLimiter
;
return
_max_concurrency
.
load
(
butil
::
memory_order_relaxed
)
;
}
}
void
ConstantConcurrencyLimiter
::
Destroy
()
{
ConstantConcurrencyLimiter
*
delete
this
;
ConstantConcurrencyLimiter
::
New
(
const
AdaptiveMaxConcurrency
&
amc
)
const
{
CHECK_EQ
(
amc
.
type
(),
AdaptiveMaxConcurrency
::
CONSTANT
());
return
new
ConstantConcurrencyLimiter
(
static_cast
<
int
>
(
amc
));
}
}
}
// namespace policy
}
// namespace policy
...
...
src/brpc/policy/constant_concurrency_limiter.h
View file @
2cb180f3
...
@@ -24,19 +24,18 @@ namespace policy {
...
@@ -24,19 +24,18 @@ namespace policy {
class
ConstantConcurrencyLimiter
:
public
ConcurrencyLimiter
{
class
ConstantConcurrencyLimiter
:
public
ConcurrencyLimiter
{
public
:
public
:
ConstantConcurrencyLimiter
()
:
_current_concurrency
(
0
)
{}
explicit
ConstantConcurrencyLimiter
(
int
max_concurrency
);
~
ConstantConcurrencyLimiter
()
{}
bool
OnRequested
(
int
current_concurrency
)
override
;
bool
OnRequested
()
override
;
void
OnResponded
(
int
error_code
,
int64_t
latency_us
)
override
;
void
OnResponded
(
int
error_code
,
int64_t
latency_us
)
override
;
int
Expose
(
const
butil
::
StringPiece
&
prefix
)
override
;
int
MaxConcurrency
(
)
override
;
ConstantConcurrencyLimiter
*
New
()
const
override
;
void
Destroy
()
override
;
ConstantConcurrencyLimiter
*
New
(
const
AdaptiveMaxConcurrency
&
)
const
override
;
private
:
private
:
butil
::
atomic
<
int
32_t
>
_current
_concurrency
;
butil
::
atomic
<
int
>
_max
_concurrency
;
};
};
}
// namespace policy
}
// 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