[gst-devel] cothreads.[ch] patch

Thomas Vander Stichele thomas at urgent.rug.ac.be
Tue Jul 2 09:15:10 CEST 2002


Hi,

attached is a patch that tries to abstract the COTHREAD_ATOMIC - dependent 
code.  I am open for suggestions to do it in a better way but this looks 
like a good start to me.

Similar fixes can be made to other parts of the code, I just want to know 
if people agree with me doing it like this.

Also, can someone who has COTHREAD_ATOMIC defined on his system try the 
patch ? I saw some weird code in the original bits that led me to believe 
it might not even have compiled correctly.  Is anybody using gstreamer 
with this defined ?

Let me know if I cocked up some of it in that case, I don't have it 
defined so  ican't test.

Thanks,
Thomas

-- 

The Dave/Dina Project : future TV today ! - http://davedina.apestaart.org/
<-*-                      -*->
That's all changed for good
No more worries and doubts
The good will come out
<-*- thomas at apestaart.org -*->
URGent, the best radio on the Internet - 24/7 ! - http://urgent.rug.ac.be/
-------------- next part --------------
Index: cothreads.c
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.c,v
retrieving revision 1.75
diff -r1.75 cothreads.c
105,109c105
< #ifdef COTHREAD_ATOMIC
<   atomic_set (&ctx->threads[0]->lock, 0);
< #else
<   ctx->threads[0]->lock = g_mutex_new ();
< #endif
---
>   _lock_new (ctx->threads[0]->lock);
217,221c213
< #ifdef COTHREAD_ATOMIC
<   atomic_set (thread->lock, 0);
< #else
<   thread->lock = g_mutex_new ();
< #endif
---
>   _lock_new (thread->lock);
266,268c258
< #ifndef COTHREAD_ATOMIC
<   g_mutex_free (thread->lock);
< #endif
---
>   _lock_free (thread->lock);
309,314c299
< #ifdef COTHREAD_ATOMIC
<     /* FIXME: I don't think we need to do anything to an atomic lock */
< #else
<     //g_mutex_free (thread->lock);
<     //thread->lock = NULL;
< #endif
---
>     _lock_free (thread->lock);
589,593c574
< #ifdef COTHREAD_ATOMIC
<   /* do something to unlock the cothread */
< #else
<   g_mutex_unlock (current->lock);
< #endif
---
>   _lock_unlock (current->lock);
596,600c577
< #ifdef COTHREAD_ATOMIC
<   /* do something to lock the cothread */
< #else
<   g_mutex_lock (thread->lock);
< #endif
---
>   _lock_lock (thread->lock);
668,673c645
< #ifdef COTHREAD_ATOMIC
<   /* do something to lock the cothread */
< #else
<   if (thread->lock)
<     g_mutex_lock (thread->lock);
< #endif
---
>   _lock_lock (thread->lock);
687,694c659
< #ifdef COTHREAD_ATOMIC
<   /* do something to try to lock the cothread */
< #else
<   if (thread->lock)
<     return g_mutex_trylock (thread->lock);
<   else
<     return FALSE;
< #endif
---
>   _lock_trylock (thread->lock);
706,711c671
< #ifdef COTHREAD_ATOMIC
<   /* do something to unlock the cothread */
< #else
<   if (thread->lock)
<     g_mutex_unlock (thread->lock);
< #endif
---
>   _lock_unlock (thread->lock);
Index: cothreads.h
===================================================================
RCS file: /cvsroot/gstreamer/gstreamer/gst/cothreads.h,v
retrieving revision 1.24
diff -r1.24 cothreads.h
46a47,96
> /* moved the COTHREAD_ATOMIC dependent stuff here instead of littered around
>  * the code as previous */
> 
> /* _lock_t type */
> #ifdef COTHREAD_ATOMIC
> typedef atomic_t _lock_t;
> #else
> typedef GMutex * _lock_t;
> #endif
> 
> /* _lock_new macro */
> #ifdef COTHREAD_ATOMIC
> #  define _lock_new(x)  atomic_set (x, 0);
> #else
> #  define _lock_new(x)  x = g_mutex_new ();
> #endif
>     
> /* _lock_free macro */
> #ifdef COTHREAD_ATOMIC
> #  define _lock_free(x) atomic_set (x, 0);
> #else
> #  define _lock_free(x) g_mutex_free (x);
> #endif
> 
> /* _lock_lock macro */
> #ifdef COTHREAD_ATOMIC
> #  define _lock_lock(x) atomic_set (x, 1);
> #else
> #  define _lock_lock(x) if (x) { g_mutex_lock (x); }
> #endif
> 
> /* _lock_unlock macro */
> #ifdef COTHREAD_ATOMIC
> #  define _lock_unlock(x) atomic_set (x, 0);
> #else
> #  define _lock_unlock(x) if (x) { g_mutex_unlock (x); }
> #endif
> 
> /* _lock_trylock macro */
> #ifdef COTHREAD_ATOMIC
> #  define _lock_trylock(x) \
>   if (atomic_read (x) == 1) \
>     return FALSE; \
>   else { \
>     _lock_lock(x); \
>     return TRUE; }
> #else
> #  define _lock_trylock(x) g_mutex_trylock (x);
> #endif
>     
64,68c114
< #ifdef COTHREAD_ATOMIC
<   atomic_t lock;
< #else
<   GMutex *lock;
< #endif
---
>   _lock_t lock;


More information about the gstreamer-devel mailing list