Yeah, this code is just defining the function using non-atomic operations.  I 
would expect all sorts of thread-related bugs to result.

Is this using gcc (you said Fedora)?  Which version?  We ought to be able to 
just use the gcc intrinsics as we do for Linux, no?

        -- lg


On Jan 2, 2013, at 9:18 AM, Richard Shaw wrote:

> I apologize if this has been discussed before. It seems familiar but
> I've slept too many time since.
> 
> Apparently there is some interest in Fedora for building OpenImageIO
> for PPC architectures and a patch was created to get oiio 1.0.X to
> build on PPC Linux (32bit I'm assuming).
> 
> I'll post the patch at the bottom but the interesting hunk in thread.h is:
> 
> @@ -272,6 +272,11 @@
> #elif defined(_WIN32)
>     // Windows
>     return _InterlockedExchangeAdd ((volatile LONG *)at, x);
> +#elif defined (__PPC__)
> +   long long r;
> +   r = *at;
> +   *at += x;
> +   return r;
> #else
> #   error No atomics on this platform.
> #endif
> 
> I seem to remember someone telling me this is essentially faking
> atomics for PPC? Does PPC not have atomics?
> 
> The reason I ask is that the patch is not applying in 1.1.2 so I
> figured I'd ask for some guidence here instead of doing a hack on the
> existing patch.
> 
> Thanks,
> Richard
> 
> Here's the whole patch:
> diff -Naur OpenImageIO-oiio-2939154.orig/src/include/thread.h
> OpenImageIO-oiio-2939154/src/include/thread.h
> --- OpenImageIO-oiio-2939154.orig/src/include/thread.h  2012-06-04
> 12:30:16.000000000 -0500
> +++ OpenImageIO-oiio-2939154/src/include/thread.h       2012-06-13
> 15:14:36.648990016 -0500
> @@ -103,7 +103,7 @@
> #endif
> 
> #if defined(__GNUC__) && (defined(_GLIBCXX_ATOMIC_BUILTINS) ||
> (__GNUC__ * 100 + __GNUC_MINOR__ >= 401))
> -#if !defined(__FreeBSD__) || defined(__x86_64__)
> +#if !defined(__FreeBSD__) && !defined(__PPC__) || defined(__x86_64__)
> #define USE_GCC_ATOMICS
> #endif
> #endif
> @@ -272,6 +272,11 @@
> #elif defined(_WIN32)
>     // Windows
>     return _InterlockedExchangeAdd ((volatile LONG *)at, x);
> +#elif defined (__PPC__)
> +   long long r;
> +   r = *at;
> +   *at += x;
> +   return r;
> #else
> #   error No atomics on this platform.
> #endif
> @@ -297,6 +302,11 @@
> #  else
>     return InterlockedExchangeAdd64 ((volatile LONGLONG *)at, x);
> #  endif
> +#elif defined (__PPC__)
> +   long long r;
> +   r = *at;
> +   *at += x;
> +   return r;
> #else
> #   error No atomics on this platform.
> #endif
> @@ -322,6 +332,8 @@
>     return OSAtomicCompareAndSwap32Barrier (compareval, newval, at);
> #elif defined(_WIN32)
>     return (_InterlockedCompareExchange ((volatile LONG *)at, newval,
> compareval) == compareval);
> +#elif defined(__PPC__)
> +    return ((*at == compareval) ? (*at = newval), 1 : 0);
> #else
> #   error No atomics on this platform.
> #endif
> @@ -341,6 +353,8 @@
>     return OSAtomicCompareAndSwap64Barrier (compareval, newval, at);
> #elif defined(_WIN32)
>     return (_InterlockedCompareExchange64 ((volatile LONGLONG *)at,
> newval, compareval) == compareval);
> +#elif defined(__PPC__)
> +    return ((*at == compareval) ? (*at = newval), 1 : 0);
> #else
> #   error No atomics on this platform.
> #endif
> _______________________________________________
> Oiio-dev mailing list
> [email protected]
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

--
Larry Gritz
[email protected]


_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to