Commit 93ba5e32 authored by TousakaRin's avatar TousakaRin

CreateConcurrencyLimiterOrDie would not return NULL now

parent 24afccac
...@@ -20,10 +20,6 @@ namespace brpc { ...@@ -20,10 +20,6 @@ namespace brpc {
ConcurrencyLimiter* ConcurrencyLimiter::CreateConcurrencyLimiterOrDie( ConcurrencyLimiter* ConcurrencyLimiter::CreateConcurrencyLimiterOrDie(
const AdaptiveMaxConcurrency& max_concurrency) { const AdaptiveMaxConcurrency& max_concurrency) {
if (max_concurrency == "constant" && static_cast<int>(max_concurrency) == 0) {
return NULL;
}
const ConcurrencyLimiter* cl = const ConcurrencyLimiter* cl =
ConcurrencyLimiterExtension()->Find(max_concurrency.name().c_str()); ConcurrencyLimiterExtension()->Find(max_concurrency.name().c_str());
CHECK(cl != NULL) CHECK(cl != NULL)
......
...@@ -26,7 +26,7 @@ namespace brpc { ...@@ -26,7 +26,7 @@ namespace brpc {
class ConcurrencyLimiter : public Destroyable { class ConcurrencyLimiter : public Destroyable {
public: public:
ConcurrencyLimiter(): _max_concurrency(0) {} ConcurrencyLimiter() : _max_concurrency(0) {}
// This method should be called each time a request comes in. It returns // This method should be called each time a request comes in. It returns
// false when the concurrency reaches the upper limit, otherwise it // false when the concurrency reaches the upper limit, otherwise it
...@@ -56,6 +56,8 @@ public: ...@@ -56,6 +56,8 @@ public:
virtual ~ConcurrencyLimiter() {} virtual ~ConcurrencyLimiter() {}
// Create ConcurrencyLimiter* and coredump if it fails.
// Caller is responsible for Destroy() the instance after usage.
static ConcurrencyLimiter* CreateConcurrencyLimiterOrDie( static ConcurrencyLimiter* CreateConcurrencyLimiterOrDie(
const AdaptiveMaxConcurrency& max_concurrency); const AdaptiveMaxConcurrency& max_concurrency);
......
...@@ -40,17 +40,16 @@ public: ...@@ -40,17 +40,16 @@ public:
// Returns true if the `max_concurrency' limit is not reached. // Returns true if the `max_concurrency' limit is not reached.
bool AddConcurrency(Controller* c) { bool AddConcurrency(Controller* c) {
c->add_flag(Controller::FLAGS_ADDED_CONCURRENCY);
if (NULL != _server->_cl) { if (NULL != _server->_cl) {
c->add_flag(Controller::FLAGS_ADDED_CONCURRENCY);
return _server->_cl->OnRequested(); return _server->_cl->OnRequested();
} else { }
return true; return true;
}
} }
void RemoveConcurrency(const Controller* c) { void RemoveConcurrency(const Controller* c) {
if (c->has_flag(Controller::FLAGS_ADDED_CONCURRENCY) && if (c->has_flag(Controller::FLAGS_ADDED_CONCURRENCY)){
NULL != _server->_cl) { CHECK(_server->_cl != NULL)
_server->_cl->OnResponded(c->ErrorCode(), c->latency_us()); _server->_cl->OnResponded(c->ErrorCode(), c->latency_us());
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment