Skip to content

Commit

Permalink
Cleaning for OMRPORT_CPU_BOUND
Browse files Browse the repository at this point in the history
This change does not fix anything patricular but provides general
cleaning of the code:
- size should have type size_t not int32_t
- memory for local variable in c-stack should be zeroed
- remove unnecessary declaration of two variables with the same name

Signed-off-by: Dmitri Pivkine <Dmitri_Pivkine@ca.ibm.com>
  • Loading branch information
dmitripivkine committed Nov 5, 2021
1 parent 2a36842 commit 2fc665e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions port/unix/omrsysinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -2731,9 +2731,12 @@ omrsysinfo_get_number_CPUs_by_type(struct OMRPortLibrary *portLibrary, uintptr_t
}
#elif defined(LINUX) && !defined(OMRZTPF)
cpu_set_t cpuSet;
int32_t size = sizeof(cpuSet); /* Size in bytes */
int32_t error = 0;
size_t size = sizeof(cpuSet); /* Size in bytes */
pid_t mainProcess = getpid();
int32_t error = sched_getaffinity(mainProcess, size, &cpuSet);
memset(&cpuSet, 0, size);

error = sched_getaffinity(mainProcess, size, &cpuSet);

if (0 == error) {
toReturn = CPU_COUNT(&cpuSet);
Expand All @@ -2744,7 +2747,7 @@ omrsysinfo_get_number_CPUs_by_type(struct OMRPortLibrary *portLibrary, uintptr_t
int32_t numCPUs = sysconf(_SC_NPROCESSORS_CONF);
cpu_set_t *allocatedCpuSet = CPU_ALLOC(numCPUs);
if (NULL != allocatedCpuSet) {
size_t size = CPU_ALLOC_SIZE(numCPUs);
size = CPU_ALLOC_SIZE(numCPUs);
CPU_ZERO_S(size, allocatedCpuSet);
error = sched_getaffinity(mainProcess, size, allocatedCpuSet);
if (0 == error) {
Expand Down

0 comments on commit 2fc665e

Please sign in to comment.