On 03/23/2014 09:52 PM, Colomban Wendling wrote:
> Le 24/03/2014 02:11, David Marceau a écrit :
>> On 03/23/2014 08:36 PM, Joël Krähemann wrote:
>>>
>>> The following will compile but is it still correct?
>>>
>>>   g_atomic_pointer_set(&(returnable_thread->safe_data),
>>>                        NULL);
>> http://developer.gimp.org/api/2.0/glib/glib-Basic-Types.html#gpointer
>> typedef void* gpointer;
>>
>> http://developer.gimp.org/api/2.0/glib/glib-Atomic-Operations.html
>> void g_atomic_pointer_set (volatile gpointer *atomic, gpointer newval);
My bad:  volatile void* *
Colomban is correct.
> 
> That's not the signature in current GLib, but that's actually correct,
> and means:
> 
> void g_atomic_pointer_set (volatile void* *atomic, gpointer newval);
> 
> hence, pointer to pointer.
> 
>> struct _AgsReturnableThread
>> {
>>   AgsThread thread;
>>   volatile guint flags;
>>   volatile void *safe_data;  // volatile gpointer safe_data
>> };
>>
>> safe_data holds the address pointing to a void value(unassigned type).
>> By putting &(blah->safe_data), you are asking for the address of the
>> address pointing to a void value.  That's not what you want.
> 
> Yes it is.  The atomic pointer functions expect a pointer to the pointer
> to atomically set, not the pointer to set itself.
> 
>> Just put (blah->safe_data, NULL).
>> The compiler shouldn't complain.
> 
> it shouldn't using a real function, but then it would crash at runtime.
>  Anyway, GLib has various compiler-specific implementation of the atomic
> operations, and the GCC one uses macros, which will detect the
> dereference of that pointer to void, which is invalid C.
> 
> The macros does basically (a lot simplified):
> 
> #define g_atomic_pointer_set(ptr, valure) \
>       ({ \
>               *(ptr) = (value); \
>               __sync(); \
>       })
> 
>> If it does, you could cast blah->safe_data with
>> (volatile void*)(blah->safe_data)
>>
>> or
>>
>> (volatile gpointer)(blah->safe_data)
> 
> That's not a wise idea in case it'd hide some real issue, nor of any
> use, in C any pointer is a valid void*.  And it wouldn't help here.
> 
> Cheers,
> Colomban
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
> 

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to