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

Commit a35e97cd authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fixed race condition in ConcurrentQueue"

parents e483ec7b 6fee6289
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -19,9 +19,6 @@

#include <gtest/gtest.h>

#include <vehicle_hal_manager/VehiclePropConfigIndex.h>
#include <VehicleHal.h>
#include <vehicle_hal_manager/VehicleHalManager.h>
#include "vehicle_hal_manager/SubscriptionManager.h"

#include "VehicleHalTestUtils.h"
+8 −10
Original line number Diff line number Diff line
@@ -17,13 +17,11 @@
#include <unordered_map>
#include <iostream>

#include <utils/SystemClock.h>

#include <gtest/gtest.h>

#include <vehicle_hal_manager/VehiclePropConfigIndex.h>
#include <VehicleHal.h>
#include <vehicle_hal_manager/VehicleHalManager.h>
#include <utils/SystemClock.h>
#include "vehicle_hal_manager/SubscriptionManager.h"
#include "vehicle_hal_manager/VehicleHalManager.h"

#include "VehicleHalTestUtils.h"

@@ -429,11 +427,11 @@ TEST(HalClientVectorTest, basic) {
    clients.addOrUpdate(c2);
    ASSERT_EQ(2u, clients.size());
    ASSERT_FALSE(clients.isEmpty());
    ASSERT_GE(0, clients.indexOf(c1));
    ASSERT_GE(0, clients.remove(c1));
    ASSERT_GE(0, clients.indexOf(c1));
    ASSERT_GE(0, clients.remove(c1));
    ASSERT_GE(0, clients.remove(c2));
    ASSERT_LE(0, clients.indexOf(c1));
    ASSERT_LE(0, clients.remove(c1));
    ASSERT_GT(0, clients.indexOf(c1));  // c1 was already removed
    ASSERT_GT(0, clients.remove(c1));   // attempt to remove c1 again
    ASSERT_LE(0, clients.remove(c2));

    ASSERT_TRUE(clients.isEmpty());
}
+2 −1
Original line number Diff line number Diff line
@@ -18,9 +18,10 @@

#include <gtest/gtest.h>

#include <vehicle_hal_manager/VehicleObjectPool.h>
#include <utils/SystemClock.h>

#include "vehicle_hal_manager/VehicleObjectPool.h"

namespace android {
namespace hardware {
namespace vehicle {
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

#include <gtest/gtest.h>

#include <vehicle_hal_manager/VehiclePropConfigIndex.h>
#include "vehicle_hal_manager/VehiclePropConfigIndex.h"

#include "VehicleHalTestUtils.h"

+6 −11
Original line number Diff line number Diff line
@@ -108,20 +108,17 @@ public:
        mQueue = queue;
        mBatchInterval = batchInterval;

        std::thread(&BatchingConsumer<T>::runInternal, this, func).detach();
        mWorkerThread = std::thread(
            &BatchingConsumer<T>::runInternal, this, func);
    }

    void requestStop() {
        if (mState.exchange(State::STOP_REQUESTED) != State::RUNNING) {
            mState = State::STOPPED;
            mCondStopped.notify_one();
        }
        mState = State::STOP_REQUESTED;
    }

    void waitStopped() {
        std::unique_lock<std::mutex> g(mLock);
        while (State::STOPPED != mState) {
            mCondStopped.wait(g);
        if (mWorkerThread.joinable()) {
            mWorkerThread.join();
        }
    }

@@ -144,12 +141,10 @@ private:
        }

        mState = State::STOPPED;
        mCondStopped.notify_one();
    }

private:
    std::mutex mLock;
    std::condition_variable mCondStopped;
    std::thread mWorkerThread;

    std::atomic<State> mState;
    std::chrono::nanoseconds mBatchInterval;