__sync_bool_compare_and_swap and structures

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi everyone,

i have written a couple of algorithms using the GCC builtin CAS, which
all works very nicely. it is a bit ugly and full of casts, and i am
trying to clean it up. i stumbled over something that i can't really
resolve however, and was wondering how other people do that:


// we are on 32bit, so this structure is 64 bits, just like a long long
struct gptr {
	void *ptr;
	int gen;
};

int main(int argc, char *argv[]) {
	long long a, b;
	long long *A = &a;

	// works as expected
	while (!__sync_bool_compare_and_swap(A, a, b)) {};

	struct gptr c, d;
	struct gptr *C = &c;

	// incompatible type for argument 1 of `__sync_bool_compare_and_swap'
	while (!__sync_bool_compare_and_swap(C, c, d)) {};

	// works but is really ugly
	while (!__sync_bool_compare_and_swap((long long*)C, 
		*(long long*)&c, *(long long*)&d)) {};

	return 0;
}

as you can see i can use CAS on 8 byte primitives (long long int) quite
well, but if i use an equal sized struct instead i get an error. i can
of course cast it as shown above, but i was hoping that i just miss
something and that it can be done cleanly.

how are you guys doing that?

cu  robert

-- 
Robert Lemmen                               http://www.semistable.com 

Attachment: signature.asc
Description: Digital signature


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux