mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-11-04 10:08:56 +01:00 
			
		
		
		
	Merge branch 'fix-ncpu' into 'main'
Don't assume CPU_ISSET will return 0 or 1 See merge request GNOME/glib!3979
This commit is contained in:
		@@ -1092,7 +1092,6 @@ g_get_num_processors (void)
 | 
				
			|||||||
    return count;
 | 
					    return count;
 | 
				
			||||||
#elif defined(_SC_NPROCESSORS_ONLN) && defined(THREADS_POSIX) && defined(HAVE_PTHREAD_GETAFFINITY_NP)
 | 
					#elif defined(_SC_NPROCESSORS_ONLN) && defined(THREADS_POSIX) && defined(HAVE_PTHREAD_GETAFFINITY_NP)
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    int idx;
 | 
					 | 
				
			||||||
    int ncores = MIN (sysconf (_SC_NPROCESSORS_ONLN), CPU_SETSIZE);
 | 
					    int ncores = MIN (sysconf (_SC_NPROCESSORS_ONLN), CPU_SETSIZE);
 | 
				
			||||||
    cpu_set_t cpu_mask;
 | 
					    cpu_set_t cpu_mask;
 | 
				
			||||||
    CPU_ZERO (&cpu_mask);
 | 
					    CPU_ZERO (&cpu_mask);
 | 
				
			||||||
@@ -1100,8 +1099,7 @@ g_get_num_processors (void)
 | 
				
			|||||||
    int af_count = 0;
 | 
					    int af_count = 0;
 | 
				
			||||||
    int err = pthread_getaffinity_np (pthread_self (), sizeof (cpu_mask), &cpu_mask);
 | 
					    int err = pthread_getaffinity_np (pthread_self (), sizeof (cpu_mask), &cpu_mask);
 | 
				
			||||||
    if (!err)
 | 
					    if (!err)
 | 
				
			||||||
      for (idx = 0; idx < ncores && idx < CPU_SETSIZE; ++idx)
 | 
					      af_count = CPU_COUNT (&cpu_mask);
 | 
				
			||||||
        af_count += CPU_ISSET (idx, &cpu_mask);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    int count = (af_count > 0) ? af_count : ncores;
 | 
					    int count = (af_count > 0) ? af_count : ncores;
 | 
				
			||||||
    return count;
 | 
					    return count;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user