File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -957,11 +957,13 @@ io_pathconf(VALUE io, VALUE arg)
957
957
static int
958
958
etc_nprocessors_affin (void )
959
959
{
960
- cpu_set_t * cpuset ;
960
+ cpu_set_t * cpuset , cpuset_buff [ 1024 / sizeof ( cpu_set_t )] ;
961
961
size_t size ;
962
962
int ret ;
963
963
int n ;
964
964
965
+ CPU_ZERO_S (sizeof (cpuset_buff ), cpuset_buff );
966
+
965
967
/*
966
968
* XXX:
967
969
* man page says CPU_ALLOC takes number of cpus. But it is not accurate
@@ -980,13 +982,12 @@ etc_nprocessors_affin(void)
980
982
*/
981
983
for (n = 64 ; n <= 16384 ; n *= 2 ) {
982
984
size = CPU_ALLOC_SIZE (n );
983
- if (size >= 1024 ) {
985
+ if (size >= sizeof ( cpuset_buff ) ) {
984
986
cpuset = xcalloc (1 , size );
985
987
if (!cpuset )
986
988
return -1 ;
987
989
} else {
988
- cpuset = alloca (size );
989
- CPU_ZERO_S (size , cpuset );
990
+ cpuset = cpuset_buff ;
990
991
}
991
992
992
993
ret = sched_getaffinity (0 , size , cpuset );
@@ -995,10 +996,10 @@ etc_nprocessors_affin(void)
995
996
ret = CPU_COUNT_S (size , cpuset );
996
997
}
997
998
998
- if (size >= 1024 ) {
999
+ if (size >= sizeof ( cpuset_buff ) ) {
999
1000
xfree (cpuset );
1000
1001
}
1001
- if (ret > 0 ) {
1002
+ if (ret > 0 || errno != EINVAL ) {
1002
1003
return ret ;
1003
1004
}
1004
1005
}
You can’t perform that action at this time.
0 commit comments