In case you would have UINT32_MAX - 1 CPUs, you would round up to return UINT32_MAX CPUs.
*val = 1;
return true;
}
-
- cpu_count = (double) quota / period;
- if (cpu_count < UINT32_MAX - 1)
- {
- // round up
- *val = (uint32_t)(cpu_count + 0.999999999);
- }
- else
- {
- *val = UINT32_MAX;
- }
+
+ // Calculate cpu count based on quota and round it up
+ cpu_count = (double) quota / period + 0.999999999;
+ *val = (cpu_count < UINT32_MAX) ? (uint32_t)cpu_count : UINT32_MAX;
return true;
}
return true;
}
- cpu_count = (double) quota / period;
- if (cpu_count < UINT_MAX - 1)
- {
- // round up
- *val = (UINT)(cpu_count + 0.999999999);
- }
- else
- {
- *val = UINT_MAX;
- }
+ // Calculate cpu count based on quota and round it up
+ cpu_count = (double) quota / period + 0.999999999;
+ *val = (cpu_count < UINT_MAX) ? (UINT)cpu_count : UINT_MAX;
return true;
}