[FFmpeg-devel] [PATCH/RFC] Trac ticket 2363
Michael Niedermayer
michaelni at gmx.at
Sun Mar 17 22:37:53 CET 2013
On Sun, Mar 17, 2013 at 06:27:28PM -0300, James Almer wrote:
> lavu/atomic.c is not compiling with gcc when using -march=i386 and w32threads
> or os2threads because __sync_val_compare_and_swap() is not defined and the
> fallback implementation currently only supports pthreads.
> Mingw-w64 has MemoryBarrier() defined even when using -march=i386, so this is
> not as much of a problem as it is with mingw32.
>
> I was able to make it work using the pthreads wrappers from libavcodec, but
> I'm not sure if this is a proper fix or not since threading is not my field of
> expertise.
>
> I'm attaching two versions of the proposed patch. Both are essentially the
> same, but one alters the pthreads implementation for the sake of cleaner code.
> I didn't test with the pthreads wrapper for os2threads because i have no way
> to do it, but in theory it should work as well.
>
> I'll send an actual patch once (and if) one of these is accepted.
>
> Regards.
> atomic.c | 27 +++++++++++++++++++--------
> 1 file changed, 19 insertions(+), 8 deletions(-)
> d2f851be5ec4d25c4b655b6a5cef60594edf989e atomic.diff
> diff --git a/libavutil/atomic.c b/libavutil/atomic.c
> index 7a701e1..12537ad 100644
> --- a/libavutil/atomic.c
> +++ b/libavutil/atomic.c
> @@ -22,38 +22,50 @@
>
> #if !HAVE_MEMORYBARRIER && !HAVE_SYNC_VAL_COMPARE_AND_SWAP && !HAVE_MACHINE_RW_BARRIER
>
> -#if HAVE_PTHREADS
> +#if HAVE_THREADS
>
> +#if HAVE_PTHREADS
> #include <pthread.h>
> +#elif HAVE_W32THREADS
> +#include "w32pthreads.h"
> +#elif HAVE_OS2THREADS
> +#include "os2threads.h"
> +#endif
>
> -static pthread_mutex_t atomic_lock = PTHREAD_MUTEX_INITIALIZER;
> +static pthread_mutex_t atomic_lock;
>
> int avpriv_atomic_int_get(volatile int *ptr)
> {
> int res;
>
> + pthread_mutex_init(&atomic_lock, NULL);
> pthread_mutex_lock(&atomic_lock);
> res = *ptr;
> pthread_mutex_unlock(&atomic_lock);
> + pthread_mutex_destroy(&atomic_lock);
>
> return res;
a mutex must be created once and shared between code you cant
create a mutex lock it unlock it and destroy it
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Avoid a single point of failure, be that a person or equipment.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20130317/02e76c56/attachment.asc>
More information about the ffmpeg-devel
mailing list