mirror of
				https://github.com/nyanmisaka/ffmpeg-rockchip.git
				synced 2025-10-31 04:26:37 +08:00 
			
		
		
		
	avutil/cpu: Fix race condition in av_cpu_count()
av_cpu_count() intends to emit a debug message containing the number of logical cores when called the first time. The check currently works with a static volatile int; yet this does not help at all in case of concurrent accesses by multiple threads. So replace this with an atomic_int. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
This commit is contained in:
		 Andreas Rheinhardt
					Andreas Rheinhardt
				
			
				
					committed by
					
						 Andreas Rheinhardt
						Andreas Rheinhardt
					
				
			
			
				
	
			
			
			 Andreas Rheinhardt
						Andreas Rheinhardt
					
				
			
						parent
						
							f38f791a23
						
					
				
				
					commit
					a2a38b1606
				
			| @@ -274,7 +274,7 @@ int av_parse_cpu_caps(unsigned *flags, const char *s) | |||||||
|  |  | ||||||
| int av_cpu_count(void) | int av_cpu_count(void) | ||||||
| { | { | ||||||
|     static volatile int printed; |     static atomic_int printed = ATOMIC_VAR_INIT(0); | ||||||
|  |  | ||||||
|     int nb_cpus = 1; |     int nb_cpus = 1; | ||||||
| #if HAVE_WINRT | #if HAVE_WINRT | ||||||
| @@ -306,10 +306,8 @@ int av_cpu_count(void) | |||||||
|     nb_cpus = sysinfo.dwNumberOfProcessors; |     nb_cpus = sysinfo.dwNumberOfProcessors; | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
|     if (!printed) { |     if (!atomic_exchange_explicit(&printed, 1, memory_order_relaxed)) | ||||||
|         av_log(NULL, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus); |         av_log(NULL, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus); | ||||||
|         printed = 1; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     return nb_cpus; |     return nb_cpus; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user