Skip to content

Commit

Permalink
Merge pull request #204 from baidu/issue_203
Browse files Browse the repository at this point in the history
use atomic counter as flags in thread_group_impl, ref issue #203
  • Loading branch information
qinzuoyan authored Aug 8, 2017
2 parents daaa35b + a502524 commit c2cf352
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/sofa/pbrpc/thread_group_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include <sofa/pbrpc/io_service.h>
#include <sofa/pbrpc/ext_closure.h>
#include <sofa/pbrpc/counter.h>

namespace sofa {
namespace pbrpc {
Expand All @@ -34,11 +35,10 @@ class ThreadGroupImpl
IOService* io_service;
ThreadInitFunc init_func;
ThreadDestFunc dest_func;
bool init_done;
bool init_fail;
AtomicCounter init_done;
AtomicCounter init_fail;

ThreadParam() : id(0), io_service(NULL), init_func(NULL), dest_func(NULL),
init_done(false), init_fail(false) {}
ThreadParam() : id(0), io_service(NULL), init_func(NULL), dest_func(NULL) {}
~ThreadParam() {}
};
public:
Expand Down Expand Up @@ -130,9 +130,9 @@ class ThreadGroupImpl
int done_num = 0;
for (int i = 0; i < _thread_num; ++i)
{
if (_thread_params[i].init_done)
if (_thread_params[i].init_done == 1)
{
if (_thread_params[i].init_fail)
if (_thread_params[i].init_fail == 1)
{
init_fail = true;
break;
Expand Down Expand Up @@ -252,11 +252,11 @@ class ThreadGroupImpl
#else
SLOG(ERROR, "thread_run(): init thread [%d] failed", thread_param->id);
#endif
thread_param->init_fail = true;
++thread_param->init_fail;
}
thread_param->init_done = true;
++thread_param->init_done;
// run asio
if (!thread_param->init_fail)
if (thread_param->init_fail == 0)
{
thread_param->io_service->run();
}
Expand Down

0 comments on commit c2cf352

Please sign in to comment.