Skip to content

Commit 55de15c

Browse files
committed
fix ~workerpool by using AutoContext
1 parent 7fd09de commit 55de15c

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

thread/test/test-pool.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,21 @@ TEST(workpool, async_work_lambda_threadpool) {
247247
LOG_INFO("DONE");
248248
}
249249

250+
TEST(workpool, std_context) {
251+
std::thread test([]{
252+
WorkPool pool(8);
253+
EXPECT_EQ(pool.get_vcpu_num(), 8);
254+
photon::spinlock lock;
255+
auto func = new auto([&]{ lock.lock(); });
256+
pool.call<StdContext>(*func);
257+
EXPECT_TRUE(lock.locked());
258+
lock.unlock();
259+
pool.async_call(func);
260+
while(!lock.locked());
261+
});
262+
test.join();
263+
}
264+
250265
TEST(workpool, async_work_lambda_threadpool_append) {
251266
std::unique_ptr<WorkPool> pool(new WorkPool(0, 0, 0, 0));
252267

thread/thread.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ namespace photon
219219
return (likely(!load()) &&
220220
likely(!xchg())) ? 0 : -1;
221221
}
222+
bool locked() const {
223+
return _lock;
224+
}
222225
void unlock() {
223226
_lock.store(false, std::memory_order_release);
224227
}

thread/workerpool.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class WorkPool::impl {
5454
}
5555

5656
~impl() { // avoid depending on photon to make it destructible wihout photon
57-
for (auto num = vcpus.size(); num; --num) enqueue({}, PhotonContext());
57+
for (auto num = vcpus.size(); num; --num) enqueue({});
5858
for (auto &worker : owned_std_threads) worker.join();
5959
while (vcpus.size()) std::this_thread::yield();
6060
}

0 commit comments

Comments
 (0)