OpenImageIO/oiio — pull request #865 by lgritz (2014-05-26 22:41:57+00:00)
Title: Another thread intrinsic path that works for gcc >= 4.8

Something I was fooling around with over the weekend, inspired by oiio-dev discussion with Matteo Vescovi.

We historically have used the __sync_* intrinsics with gcc and clang for atomic operations (since, alas, we cannot yet count on C++11 or C11 compatibility among our users). Matteo points out that these intrinsics may work on i386 and x86_64, but are not available on PowerPC, MIPS, and SPARC. But, as long as they are using a fairly modern gcc, there is a new set of intrinsics, __atomic_*, that seem to work on all platforms.

So this patch adds yet another clause to various #if statements in thread.h, using the newer gcc intrinsics when available (I use >= gcc 4.8 as the deciding factor, it's possible that it may also work for 4.7, but I wasn't positive and Matteo is using 4.8 on those difficult platforms anyway). For older versions of gcc, and for clang, we fall back to the __sync just like we always did. I ran some benchmarks and the two sets of intrinsics appear to perform about equally well and all unit tests pass so I'm fairly certain they are correct.

I intend to backport this to RB-1.4, so that 1.4 can be made to work on those platforms, but I'll let this sit in master for a week or two first before I backport it, just to be sure that there aren't any problems discovered.