Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 51a36dd9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Fixes dumpstate crashed when shutdown the thread pool" am: 6fe1d3d3 am: bb0e037a

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1641960

Change-Id: I79cc42333f9b8cc9d97ddc860fadd64a0ace8120
parents a6926bd1 bb0e037a
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -64,8 +64,8 @@ void DumpPool::shutdown() {
    if (shutdown_ || threads_.empty()) {
    if (shutdown_ || threads_.empty()) {
        return;
        return;
    }
    }
    while (!tasks_.empty()) tasks_.pop();
    futures_map_.clear();
    futures_map_.clear();
    while (!tasks_.empty()) tasks_.pop();


    shutdown_ = true;
    shutdown_ = true;
    condition_variable_.notify_all();
    condition_variable_.notify_all();
+21 −0
Original line number Original line Diff line number Diff line
@@ -1762,6 +1762,27 @@ TEST_F(DumpPoolTest, EnqueueTask_withDurationLog) {
    EXPECT_THAT(getTempFileCounts(kTestDataPath), Eq(0));
    EXPECT_THAT(getTempFileCounts(kTestDataPath), Eq(0));
}
}


TEST_F(DumpPoolTest, Shutdown_withoutCrash) {
    bool run_1 = false;
    auto dump_func_1 = [&]() {
        run_1 = true;
    };
    auto dump_func = []() {
        sleep(1);
    };

    dump_pool_->start(/* thread_counts = */1);
    dump_pool_->enqueueTask(/* task_name = */"1", dump_func_1);
    dump_pool_->enqueueTask(/* task_name = */"2", dump_func);
    dump_pool_->enqueueTask(/* task_name = */"3", dump_func);
    dump_pool_->enqueueTask(/* task_name = */"4", dump_func);
    dump_pool_->waitForTask("1", "", out_fd_.get());
    dump_pool_->shutdown();

    EXPECT_TRUE(run_1);
    EXPECT_THAT(getTempFileCounts(kTestDataPath), Eq(0));
}

class TaskQueueTest : public DumpstateBaseTest {
class TaskQueueTest : public DumpstateBaseTest {
public:
public:
    void SetUp() {
    void SetUp() {