mirror of
https://github.com/valitydev/thrift.git
synced 2024-11-07 02:45:22 +00:00
THRIFT-3233 fix accounting of workers in thread manager
Client: C++ Patch: Jim King <jim.king@simplivity.com> This closes #992
This commit is contained in:
parent
a52ea350d8
commit
61b170845f
@ -213,8 +213,6 @@ public:
|
|||||||
*/
|
*/
|
||||||
void run() {
|
void run() {
|
||||||
bool active = false;
|
bool active = false;
|
||||||
bool notifyManager = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Increment worker semaphore and notify manager if worker count reached
|
* Increment worker semaphore and notify manager if worker count reached
|
||||||
* desired max
|
* desired max
|
||||||
@ -223,18 +221,20 @@ public:
|
|||||||
* since that is what the manager blocks on for worker add/remove
|
* since that is what the manager blocks on for worker add/remove
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
Synchronized s(manager_->monitor_);
|
bool notifyManager = false;
|
||||||
active = manager_->workerCount_ < manager_->workerMaxCount_;
|
{
|
||||||
if (active) {
|
Synchronized s(manager_->monitor_);
|
||||||
manager_->workerCount_++;
|
active = manager_->workerCount_ < manager_->workerMaxCount_;
|
||||||
notifyManager = manager_->workerCount_ == manager_->workerMaxCount_;
|
if (active) {
|
||||||
|
manager_->workerCount_++;
|
||||||
|
notifyManager = manager_->workerCount_ == manager_->workerMaxCount_;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (notifyManager) {
|
if (notifyManager) {
|
||||||
Synchronized s(manager_->workerMonitor_);
|
Synchronized s(manager_->workerMonitor_);
|
||||||
manager_->workerMonitor_.notify();
|
manager_->workerMonitor_.notify();
|
||||||
notifyManager = false;
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (active) {
|
while (active) {
|
||||||
@ -279,10 +279,6 @@ public:
|
|||||||
&& manager_->tasks_.size() <= manager_->pendingTaskCountMax_ - 1) {
|
&& manager_->tasks_.size() <= manager_->pendingTaskCountMax_ - 1) {
|
||||||
manager_->maxMonitor_.notify();
|
manager_->maxMonitor_.notify();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
idle_ = true;
|
|
||||||
manager_->workerCount_--;
|
|
||||||
notifyManager = (manager_->workerCount_ == manager_->workerMaxCount_);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,6 +298,9 @@ public:
|
|||||||
{
|
{
|
||||||
Synchronized s(manager_->workerMonitor_);
|
Synchronized s(manager_->workerMonitor_);
|
||||||
manager_->deadWorkers_.insert(this->thread());
|
manager_->deadWorkers_.insert(this->thread());
|
||||||
|
idle_ = true;
|
||||||
|
manager_->workerCount_--;
|
||||||
|
bool notifyManager = (manager_->workerCount_ == manager_->workerMaxCount_);
|
||||||
if (notifyManager) {
|
if (notifyManager) {
|
||||||
manager_->workerMonitor_.notify();
|
manager_->workerMonitor_.notify();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user