Merge "race condition in libprocessgroup"
This commit is contained in:
commit
aba081c119
2 changed files with 5 additions and 0 deletions
|
|
@ -150,6 +150,7 @@ SetCgroupAction::SetCgroupAction(const CgroupController& c, const std::string& p
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetCgroupAction::EnableResourceCaching() {
|
void SetCgroupAction::EnableResourceCaching() {
|
||||||
|
std::lock_guard<std::mutex> lock(fd_mutex_);
|
||||||
if (fd_ != FDS_NOT_CACHED) {
|
if (fd_ != FDS_NOT_CACHED) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -191,6 +192,7 @@ bool SetCgroupAction::AddTidToCgroup(int tid, int fd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetCgroupAction::ExecuteForProcess(uid_t uid, pid_t pid) const {
|
bool SetCgroupAction::ExecuteForProcess(uid_t uid, pid_t pid) const {
|
||||||
|
std::lock_guard<std::mutex> lock(fd_mutex_);
|
||||||
if (IsFdValid()) {
|
if (IsFdValid()) {
|
||||||
// fd is cached, reuse it
|
// fd is cached, reuse it
|
||||||
if (!AddTidToCgroup(pid, fd_)) {
|
if (!AddTidToCgroup(pid, fd_)) {
|
||||||
|
|
@ -221,6 +223,7 @@ bool SetCgroupAction::ExecuteForProcess(uid_t uid, pid_t pid) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetCgroupAction::ExecuteForTask(int tid) const {
|
bool SetCgroupAction::ExecuteForTask(int tid) const {
|
||||||
|
std::lock_guard<std::mutex> lock(fd_mutex_);
|
||||||
if (IsFdValid()) {
|
if (IsFdValid()) {
|
||||||
// fd is cached, reuse it
|
// fd is cached, reuse it
|
||||||
if (!AddTidToCgroup(tid, fd_)) {
|
if (!AddTidToCgroup(tid, fd_)) {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <mutex>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
@ -127,6 +128,7 @@ class SetCgroupAction : public ProfileAction {
|
||||||
CgroupController controller_;
|
CgroupController controller_;
|
||||||
std::string path_;
|
std::string path_;
|
||||||
android::base::unique_fd fd_;
|
android::base::unique_fd fd_;
|
||||||
|
mutable std::mutex fd_mutex_;
|
||||||
|
|
||||||
static bool IsAppDependentPath(const std::string& path);
|
static bool IsAppDependentPath(const std::string& path);
|
||||||
static bool AddTidToCgroup(int tid, int fd);
|
static bool AddTidToCgroup(int tid, int fd);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue