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

Commit e8305279 authored by Girish's avatar Girish
Browse files

resourcemanager: protect resources from concurrent access

Since getClient access resources (map), make sure its protected
from the concurrent access.

Bug: 289097671
Test: atest android.media.misc.cts.ResourceManagerTest
      atest android.media.misc.cts.ResourceManagerMultiTest
      /data/nativetest64/ResourceManagerService_test/ResourceManagerService_test
      /data/nativetest64/ResourceObserverService_test/ResourceObserverService_test
Change-Id: Ica03c3dc45b97502414c76c10057acc9c9b0c03d
parent d11a03a7
Loading
Loading
Loading
Loading
+8 −5
Original line number Diff line number Diff line
@@ -620,7 +620,7 @@ void ResourceManagerService::pushReclaimAtom(const ClientInfoParcel& clientInfo,
    mResourceManagerMetrics->pushReclaimAtom(clientInfo, priorities, targetClients, reclaimed);
}

std::shared_ptr<IResourceManagerClient> ResourceManagerService::getClient(
std::shared_ptr<IResourceManagerClient> ResourceManagerService::getClient_l(
        int pid, const int64_t& clientId) const {
    std::map<int, ResourceInfos>::const_iterator found = mMap.find(pid);
    if (found == mMap.end()) {
@@ -638,7 +638,7 @@ std::shared_ptr<IResourceManagerClient> ResourceManagerService::getClient(
    return foundClient->second.client;
}

bool ResourceManagerService::removeClient(int pid, const int64_t& clientId) {
bool ResourceManagerService::removeClient_l(int pid, const int64_t& clientId) {
    std::map<int, ResourceInfos>::iterator found = mMap.find(pid);
    if (found == mMap.end()) {
        ALOGV("%s: didn't find pid %d for clientId %lld", __func__, pid, (long long) clientId);
@@ -665,8 +665,11 @@ bool ResourceManagerService::reclaimUnconditionallyFrom(
    int64_t failedClientId = -1;
    int32_t failedClientPid = -1;
    for (const ClientInfo& targetClient : targetClients) {
        std::shared_ptr<IResourceManagerClient> client = getClient(
            targetClient.mPid, targetClient.mClientId);
        std::shared_ptr<IResourceManagerClient> client = nullptr;
        {
            std::scoped_lock lock{mLock};
            client = getClient_l(targetClient.mPid, targetClient.mClientId);
        }
        if (client == nullptr) {
            // skip already released clients.
            continue;
@@ -688,7 +691,7 @@ bool ResourceManagerService::reclaimUnconditionallyFrom(

    {
        std::scoped_lock lock{mLock};
        bool found = removeClient(failedClientPid, failedClientId);
        bool found = removeClient_l(failedClientPid, failedClientId);
        if (found) {
            ALOGW("Failed to reclaim resources from client with pid %d", failedClientPid);
        } else {
+2 −2
Original line number Diff line number Diff line
@@ -210,11 +210,11 @@ private:
    virtual void removeProcessInfoOverride(int pid);

    // Get the client for given pid and the clientId from the map
    virtual std::shared_ptr<IResourceManagerClient> getClient(
    virtual std::shared_ptr<IResourceManagerClient> getClient_l(
        int pid, const int64_t& clientId) const;

    // Remove the client for given pid and the clientId from the map
    virtual bool removeClient(int pid, const int64_t& clientId);
    virtual bool removeClient_l(int pid, const int64_t& clientId);

    // Get all the resource status for dump
    virtual void getResourceDump(std::string& resourceLog) const;
+2 −2
Original line number Diff line number Diff line
@@ -356,12 +356,12 @@ bool ResourceManagerServiceNew::getAllClients_l(
    return true;
}

std::shared_ptr<IResourceManagerClient> ResourceManagerServiceNew::getClient(
std::shared_ptr<IResourceManagerClient> ResourceManagerServiceNew::getClient_l(
        int pid, const int64_t& clientId) const {
    return mResourceTracker->getClient(pid, clientId);
}

bool ResourceManagerServiceNew::removeClient(int pid, const int64_t& clientId) {
bool ResourceManagerServiceNew::removeClient_l(int pid, const int64_t& clientId) {
    return mResourceTracker->removeClient(pid, clientId);
}

+2 −2
Original line number Diff line number Diff line
@@ -124,11 +124,11 @@ private:
    bool getPriority_l(int pid, int* priority) const override;

    // Get the client for given pid and the clientId from the map
    std::shared_ptr<IResourceManagerClient> getClient(
    std::shared_ptr<IResourceManagerClient> getClient_l(
        int pid, const int64_t& clientId) const override;

    // Remove the client for given pid and the clientId from the map
    bool removeClient(int pid, const int64_t& clientId) override;
    bool removeClient_l(int pid, const int64_t& clientId) override;

    // Get all the resource status for dump
    void getResourceDump(std::string& resourceLog) const override;