Skip to content

Commit

Permalink
fix a bug co::pool
Browse files Browse the repository at this point in the history
  • Loading branch information
idealvin committed Apr 23, 2022
1 parent ef10d2b commit d0edfb2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/co/co.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,11 @@ class PoolImpl {
typedef co::vector<void*> V;

PoolImpl()
: _pools(co::scheduler_num()), _maxcap((size_t)-1) {
: _pools(co::scheduler_num(), NULL), _maxcap((size_t)-1) {
}

PoolImpl(std::function<void*()>&& ccb, std::function<void(void*)>&& dcb, size_t cap)
: _pools(co::scheduler_num()), _maxcap(cap),
: _pools(co::scheduler_num(), NULL), _maxcap(cap),
_ccb(std::move(ccb)), _dcb(std::move(dcb)) {
}

Expand All @@ -252,7 +252,7 @@ inline void* PoolImpl::pop() {
CHECK(gSched) << "must be called in coroutine..";
auto& v = _pools[gSched->id()];
if (v == NULL) v = co::make<V>(1024);
if (!v->empty()) {
if (v && !v->empty()) {
return v->pop_back();
} else {
return _ccb ? _ccb() : 0;
Expand Down
4 changes: 2 additions & 2 deletions unitest/co.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ DEF_test(co) {
);

int n = co::scheduler_num();
co::vector<int> vi(n);
co::vector<int> vi(n, 0);

co::WaitGroup wg;
wg.add(n);

for (int i = 0; i < n; ++i) {
go([wg, p, i, &vi]() {
go([wg, p, i]() {
co::PoolGuard<int> g(p);
*g = i;
wg.done();
Expand Down

0 comments on commit d0edfb2

Please sign in to comment.