mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-10-31 00:12:19 +01:00 
			
		
		
		
	gatomic: Support atomic compare_and_exchange macros on older C++ standard versions
The fix in ad23894c15 only works for
__cplusplus >= 201103L, but older C++ standards are not always less strict,
and still fail to compile the g_atomic_int_compare_and_exchange() and
g_atomic_pointer_compare_and_exchange() macros.
Apply that fix to all C++ standard versions.
Even if this implies using functions that have been added as part of
C++11 specification, this is safe because we wouldn't ever try to use the
`__atomic_...()` APIs if `__ATOMIC_SEQ_CST` is not defined, and that's part
of the very same API.
			
			
This commit is contained in:
		
				
					committed by
					
						 Marco Trevisan (Treviño)
						Marco Trevisan (Treviño)
					
				
			
			
				
	
			
			
			
						parent
						
							0abb82498e
						
					
				
				
					commit
					a0f200593c
				
			| @@ -170,7 +170,7 @@ G_END_DECLS | |||||||
|     (void) (0 ? *(atomic) ^ *(atomic) : 1);                                  \ |     (void) (0 ? *(atomic) ^ *(atomic) : 1);                                  \ | ||||||
|     __atomic_fetch_sub ((atomic), 1, __ATOMIC_SEQ_CST) == 1;                 \ |     __atomic_fetch_sub ((atomic), 1, __ATOMIC_SEQ_CST) == 1;                 \ | ||||||
|   })) |   })) | ||||||
| #if defined(glib_typeof) && defined(__cplusplus) && __cplusplus >= 201103L | #if defined(glib_typeof) && defined(__cplusplus) | ||||||
| /* See comments below about equivalent g_atomic_pointer_compare_and_exchange() | /* See comments below about equivalent g_atomic_pointer_compare_and_exchange() | ||||||
|  * shenanigans for type-safety when compiling in C++ mode. */ |  * shenanigans for type-safety when compiling in C++ mode. */ | ||||||
| #define g_atomic_int_compare_and_exchange(atomic, oldval, newval) \ | #define g_atomic_int_compare_and_exchange(atomic, oldval, newval) \ | ||||||
| @@ -180,7 +180,7 @@ G_END_DECLS | |||||||
|     (void) (0 ? *(atomic) ^ (newval) ^ (oldval) : 1);                        \ |     (void) (0 ? *(atomic) ^ (newval) ^ (oldval) : 1);                        \ | ||||||
|     __atomic_compare_exchange_n ((atomic), &gaicae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \ |     __atomic_compare_exchange_n ((atomic), &gaicae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \ | ||||||
|   })) |   })) | ||||||
| #else /* if !(defined(glib_typeof) && defined(__cplusplus) && __cplusplus >= 201103L) */ | #else /* if !(defined(glib_typeof) && defined(__cplusplus)) */ | ||||||
| #define g_atomic_int_compare_and_exchange(atomic, oldval, newval) \ | #define g_atomic_int_compare_and_exchange(atomic, oldval, newval) \ | ||||||
|   (G_GNUC_EXTENSION ({                                                       \ |   (G_GNUC_EXTENSION ({                                                       \ | ||||||
|     gint gaicae_oldval = (oldval);                                           \ |     gint gaicae_oldval = (oldval);                                           \ | ||||||
| @@ -230,7 +230,7 @@ G_END_DECLS | |||||||
|     (guint) __atomic_fetch_xor ((atomic), (val), __ATOMIC_SEQ_CST);          \ |     (guint) __atomic_fetch_xor ((atomic), (val), __ATOMIC_SEQ_CST);          \ | ||||||
|   })) |   })) | ||||||
|  |  | ||||||
| #if defined(glib_typeof) && defined(__cplusplus) && __cplusplus >= 201103L | #if defined(glib_typeof) && defined(__cplusplus) | ||||||
| /* This is typesafe because we check we can assign oldval to the type of | /* This is typesafe because we check we can assign oldval to the type of | ||||||
|  * (*atomic). Unfortunately it can only be done in C++ because gcc/clang warn |  * (*atomic). Unfortunately it can only be done in C++ because gcc/clang warn | ||||||
|  * when atomic is volatile and not oldval, or when atomic is gsize* and oldval |  * when atomic is volatile and not oldval, or when atomic is gsize* and oldval | ||||||
| @@ -247,7 +247,7 @@ G_END_DECLS | |||||||
|     (void) (0 ? (gpointer) *(atomic) : NULL);                                \ |     (void) (0 ? (gpointer) *(atomic) : NULL);                                \ | ||||||
|     __atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \ |     __atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \ | ||||||
|   })) |   })) | ||||||
| #else /* if !(defined(glib_typeof) && defined(__cplusplus) && __cplusplus >= 201103L) */ | #else /* if !(defined(glib_typeof) && defined(__cplusplus) */ | ||||||
| #define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \ | #define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \ | ||||||
|   (G_GNUC_EXTENSION ({                                                       \ |   (G_GNUC_EXTENSION ({                                                       \ | ||||||
|     G_STATIC_ASSERT (sizeof (oldval) == sizeof (gpointer));                  \ |     G_STATIC_ASSERT (sizeof (oldval) == sizeof (gpointer));                  \ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user