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

Commit 4426a941 authored by Suren Baghdasaryan's avatar Suren Baghdasaryan Committed by android-build-merger
Browse files

Merge "Fix IsUsable to check for each controller separately"

am: 7e473e26

Change-Id: I85c255fdd29e805ffcac8824a4243026db872c69
parents 3418abfe 7e473e26
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -67,11 +67,14 @@ bool CgroupController::HasValue() const {
    return controller_ != nullptr;
    return controller_ != nullptr;
}
}


bool CgroupController::IsUsable() const {
bool CgroupController::IsUsable() {
    if (!HasValue()) return false;
    if (!HasValue()) return false;


    static bool enabled = (access(GetProcsFilePath("", 0, 0).c_str(), F_OK) == 0);
    if (state_ == UNKNOWN) {
    return enabled;
        state_ = access(GetProcsFilePath("", 0, 0).c_str(), F_OK) == 0 ? USABLE : MISSING;
    }

    return state_ == USABLE;
}
}


std::string CgroupController::GetTasksFilePath(const std::string& rel_path) const {
std::string CgroupController::GetTasksFilePath(const std::string& rel_path) const {
+10 −2
Original line number Original line Diff line number Diff line
@@ -31,20 +31,28 @@
class CgroupController {
class CgroupController {
  public:
  public:
    // Does not own controller
    // Does not own controller
    explicit CgroupController(const ACgroupController* controller) : controller_(controller) {}
    explicit CgroupController(const ACgroupController* controller)
        : controller_(controller), state_(UNKNOWN) {}


    uint32_t version() const;
    uint32_t version() const;
    const char* name() const;
    const char* name() const;
    const char* path() const;
    const char* path() const;


    bool HasValue() const;
    bool HasValue() const;
    bool IsUsable() const;
    bool IsUsable();


    std::string GetTasksFilePath(const std::string& path) const;
    std::string GetTasksFilePath(const std::string& path) const;
    std::string GetProcsFilePath(const std::string& path, uid_t uid, pid_t pid) const;
    std::string GetProcsFilePath(const std::string& path, uid_t uid, pid_t pid) const;
    bool GetTaskGroup(int tid, std::string* group) const;
    bool GetTaskGroup(int tid, std::string* group) const;
  private:
  private:
    enum ControllerState {
        UNKNOWN = 0,
        USABLE = 1,
        MISSING = 2,
    };

    const ACgroupController* controller_ = nullptr;
    const ACgroupController* controller_ = nullptr;
    ControllerState state_;
};
};


class CgroupMap {
class CgroupMap {