]> git.sesse.net Git - mlt/commitdiff
mlt_properties.c, mlt_service.c: bugfix to make reference counting and service closur...
authorddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 30 Jun 2008 01:53:07 +0000 (01:53 +0000)
committerddennedy <ddennedy@d19143bc-622f-0410-bfdd-b5b2a6649095>
Mon, 30 Jun 2008 01:53:07 +0000 (01:53 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@1154 d19143bc-622f-0410-bfdd-b5b2a6649095

src/framework/mlt_properties.c
src/framework/mlt_service.c

index 4e3f22bd505d3495f162f62f4dd6e8838b5c81bc..7e55da91c72d09a96025625c0b82d7c83f4d34ee 100644 (file)
@@ -28,7 +28,7 @@
 #include <string.h>
 #include <ctype.h>
 #include <stdarg.h>
-
+#include <pthread.h>
 #include <sys/types.h>
 #include <dirent.h>
 
@@ -46,6 +46,7 @@ typedef struct
        int size;
        mlt_properties mirror;
        int ref_count;
+       pthread_mutex_t mutex;
 }
 property_list;
 
@@ -82,6 +83,7 @@ int mlt_properties_init( mlt_properties this, void *child )
 
                // Increment the ref count
                ( ( property_list * )this->local )->ref_count = 1;
+               pthread_mutex_init( &( ( property_list * )this->local )->mutex, NULL );;
        }
 
        // Check that initialisation was successful
@@ -186,12 +188,15 @@ static inline void mlt_properties_do_mirror( mlt_properties this, const char *na
 
 int mlt_properties_inc_ref( mlt_properties this )
 {
+       int result = 0;
        if ( this != NULL )
        {
                property_list *list = this->local;
-               return ++ list->ref_count;
+               pthread_mutex_lock( &list->mutex );
+               result = ++ list->ref_count;
+               pthread_mutex_unlock( &list->mutex );
        }
-       return 0;
+       return result;
 }
 
 /** Maintain ref count to allow multiple uses of an mlt object.
@@ -199,12 +204,15 @@ int mlt_properties_inc_ref( mlt_properties this )
 
 int mlt_properties_dec_ref( mlt_properties this )
 {
+       int result = 0;
        if ( this != NULL )
        {
                property_list *list = this->local;
-               return -- list->ref_count;
+               pthread_mutex_lock( &list->mutex );
+               result = -- list->ref_count;
+               pthread_mutex_unlock( &list->mutex );
        }
-       return 0;
+       return result;
 }
 
 /** Return the ref count of this object.
@@ -903,6 +911,7 @@ void mlt_properties_close( mlt_properties this )
                        }
        
                        // Clear up the list
+                       pthread_mutex_destroy( &list->mutex );
                        free( list->name );
                        free( list->value );
                        free( list );
index 92018657fc1baa5528d748001305321cce3101e5..04d929aa0bf69ce837f116ed5302873df3fa5321 100644 (file)
@@ -188,11 +188,7 @@ int mlt_service_connect_producer( mlt_service this, mlt_service producer, int in
 
                // Increment the reference count on this producer
                if ( producer != NULL )
-               {
-                       mlt_service_lock( producer );
                        mlt_properties_inc_ref( MLT_SERVICE_PROPERTIES( producer ) );
-                       mlt_service_unlock( producer );
-               }
 
                // Now we disconnect the producer service from its consumer
                mlt_service_disconnect( producer );
@@ -499,10 +495,8 @@ mlt_profile mlt_service_profile( mlt_service this )
 
 void mlt_service_close( mlt_service this )
 {
-       mlt_service_lock( this );
        if ( this != NULL && mlt_properties_dec_ref( MLT_SERVICE_PROPERTIES( this ) ) <= 0 )
        {
-               mlt_service_unlock( this );
                if ( this->close != NULL )
                {
                        this->close( this->close_object );