Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
fixes for review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rahul committed Mar 22, 2017
1 parent b24a9a1 commit 8a5ca29
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 51 deletions.
48 changes: 22 additions & 26 deletions src/gc/unix/cgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class CGroup
char* mountpath = nullptr;

FILE *mountinfofile = fopen(PROC_MOUNTINFO_FILENAME, "r");
if (mountinfofile == NULL)
if (mountinfofile == nullptr)
goto done;

while (getline(&line, &lineLen, mountinfofile) != -1)
Expand Down Expand Up @@ -128,9 +128,9 @@ class CGroup

if (strncmp(filesystemType, "cgroup", 6) == 0)
{
char* context = NULL;
char* context = nullptr;
char* strTok = strtok_r(options, ",", &context);
while (strTok != NULL)
while (strTok != nullptr)
{
if (strncmp("memory", strTok, 6) == 0)
{
Expand All @@ -149,15 +149,14 @@ class CGroup
}
goto done;
}
strTok = strtok_r(NULL, ",", &context);
strTok = strtok_r(nullptr, ",", &context);
}
}
}
done:
free(filesystemType);
free(options);
if (line)
free(line);
free(line);
if (mountinfofile)
fclose(mountinfofile);
return mountpath;
Expand All @@ -173,7 +172,7 @@ class CGroup
bool result = false;

FILE *cgroupfile = fopen(PROC_CGROUP_FILENAME, "r");
if (cgroupfile == NULL)
if (cgroupfile == nullptr)
goto done;

while (!result && getline(&line, &lineLen, cgroupfile) != -1)
Expand Down Expand Up @@ -202,16 +201,16 @@ class CGroup
goto done;
}

char* context = NULL;
char* context = nullptr;
char* strTok = strtok_r(subsystem_list, ",", &context);
while (strTok != NULL)
while (strTok != nullptr)
{
if (strncmp("memory", strTok, 6) == 0)
{
result = true;
break;
}
strTok = strtok_r(NULL, ",", &context);
strTok = strtok_r(nullptr, ",", &context);
}
}
done:
Expand All @@ -221,8 +220,7 @@ class CGroup
free(cgroup_path);
cgroup_path = nullptr;
}
if (line)
free(line);
free(line);
if (cgroupfile)
fclose(cgroupfile);
return cgroup_path;
Expand All @@ -233,15 +231,15 @@ class CGroup
bool result = false;
char *line = nullptr;
size_t lineLen = 0;
char* endptr = NULL;
char* endptr = nullptr;
size_t num = 0, l, multiplier;
FILE* file = NULL;
FILE* file = nullptr;

if (val == NULL)
if (val == nullptr)
goto done;

file = fopen(filename, "r");
if (file == NULL)
if (file == nullptr)
goto done;

if (getline(&line, &lineLen, file) == -1)
Expand Down Expand Up @@ -270,8 +268,7 @@ class CGroup
done:
if (file)
fclose(file);
if (line)
free(line);
free(line);
return result;
}
};
Expand All @@ -294,14 +291,14 @@ size_t GetRestrictedPhysicalMemoryLimit()
physical_memory_limit : rlimit_soft_limit;

// Ensure that limit is not greater than real memory size
size_t pages = (size_t) sysconf(_SC_PHYS_PAGES);
long pages = sysconf(_SC_PHYS_PAGES);
if (pages != -1)
{
long pageSize = sysconf(_SC_PAGE_SIZE);
if (pageSize != -1)
{
physical_memory_limit = (physical_memory_limit < pages * pageSize)?
physical_memory_limit : pages * pageSize;
physical_memory_limit = (physical_memory_limit < (size_t)pages * pageSize)?
physical_memory_limit : (size_t)pages * pageSize;
}
}

Expand All @@ -312,13 +309,13 @@ bool GetWorkingSetSize(size_t* val)
{
bool result = false;
size_t linelen;
char* line = NULL;
char* line = nullptr;

if (val == NULL)
if (val == nullptr)
return false;

FILE* file = fopen(PROC_STATM_FILENAME, "r");
if (file != NULL && getline(&line, &linelen, file) != -1)
if (file != nullptr && getline(&line, &linelen, file) != -1)
{
if (sscanf(line, "%*s %zu %*s %*s %*s %*s %*s", val) == 1)
{
Expand All @@ -333,7 +330,6 @@ bool GetWorkingSetSize(size_t* val)

if (file)
fclose(file);
if (line)
free(line);
free(line);
return result;
}
2 changes: 1 addition & 1 deletion src/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ void GCToOSInterface::GetMemoryStatus(uint32_t* memory_load, uint64_t* available
if (total > 0 && GetWorkingSetSize(&used))
{
available = total > used ? total-used : 0;
load = (uint32_t)((used * 100) / total);
load = (uint32_t)(((float)used * 100) / (float)total);
}

if (memory_load != nullptr)
Expand Down
44 changes: 20 additions & 24 deletions src/pal/src/misc/cgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CGroup
char* mountpath = nullptr;

FILE *mountinfofile = fopen(PROC_MOUNTINFO_FILENAME, "r");
if (mountinfofile == NULL)
if (mountinfofile == nullptr)
goto done;

while (getline(&line, &lineLen, mountinfofile) != -1)
Expand Down Expand Up @@ -121,9 +121,9 @@ class CGroup

if (strncmp(filesystemType, "cgroup", 6) == 0)
{
char* context = NULL;
char* context = nullptr;
char* strTok = strtok_s(options, ",", &context);
while (strTok != NULL)
while (strTok != nullptr)
{
if (strncmp("memory", strTok, 6) == 0)
{
Expand All @@ -142,15 +142,14 @@ class CGroup
}
goto done;
}
strTok = strtok_s(NULL, ",", &context);
strTok = strtok_s(nullptr, ",", &context);
}
}
}
done:
PAL_free(filesystemType);
PAL_free(options);
if (line)
free(line);
free(line);
if (mountinfofile)
fclose(mountinfofile);
return mountpath;
Expand All @@ -166,7 +165,7 @@ class CGroup
bool result = false;

FILE *cgroupfile = fopen(PROC_CGROUP_FILENAME, "r");
if (cgroupfile == NULL)
if (cgroupfile == nullptr)
goto done;

while (!result && getline(&line, &lineLen, cgroupfile) != -1)
Expand Down Expand Up @@ -195,16 +194,16 @@ class CGroup
goto done;
}

char* context = NULL;
char* context = nullptr;
char* strTok = strtok_s(subsystem_list, ",", &context);
while (strTok != NULL)
while (strTok != nullptr)
{
if (strncmp("memory", strTok, 6) == 0)
{
result = true;
break;
}
strTok = strtok_s(NULL, ",", &context);
strTok = strtok_s(nullptr, ",", &context);
}
}
done:
Expand All @@ -214,8 +213,7 @@ class CGroup
PAL_free(cgroup_path);
cgroup_path = nullptr;
}
if (line)
free(line);
free(line);
if (cgroupfile)
fclose(cgroupfile);
return cgroup_path;
Expand All @@ -226,14 +224,14 @@ class CGroup
bool result = false;
char *line = nullptr;
size_t lineLen = 0;
char* endptr = NULL;
char* endptr = nullptr;
size_t num = 0, l, multiplier;

if (val == NULL)
if (val == nullptr)
return false;

FILE* file = fopen(filename, "r");
if (file == NULL)
if (file == nullptr)
goto done;

if (getline(&line, &lineLen, file) == -1)
Expand Down Expand Up @@ -262,8 +260,7 @@ class CGroup
done:
if (file)
fclose(file);
if (line)
free(line);
free(line);
return result;
}
};
Expand All @@ -288,14 +285,14 @@ PAL_GetRestrictedPhysicalMemoryLimit()
physical_memory_limit = min(physical_memory_limit, rlimit_soft_limit);

// Ensure that limit is not greater than real memory size
size_t pages = (size_t) sysconf(_SC_PHYS_PAGES);
long pages = sysconf(_SC_PHYS_PAGES);
if (pages != -1)
{
long pageSize = sysconf(_SC_PAGE_SIZE);
if (pageSize != -1)
{
physical_memory_limit = min(physical_memory_limit,
pages * pageSize);
(size_t)pages * pageSize);
}
}

Expand All @@ -310,13 +307,13 @@ PAL_GetWorkingSetSize(size_t* val)
{
BOOL result = false;
size_t linelen;
char* line = NULL;
char* line = nullptr;

if (val == NULL)
if (val == nullptr)
return FALSE;

FILE* file = fopen(PROC_STATM_FILENAME, "r");
if (file != NULL && getline(&line, &linelen, file) != -1)
if (file != nullptr && getline(&line, &linelen, file) != -1)
{
int x = sscanf_s(line, "%*s %llu %*s %*s %*s %*s %*s", val);
if(x == 1)
Expand All @@ -328,7 +325,6 @@ PAL_GetWorkingSetSize(size_t* val)

if (file)
fclose(file);
if (line)
free(line);
free(line);
return result;
}

0 comments on commit 8a5ca29

Please sign in to comment.