All pastes #771555 Raw Edit

travistex_jobrefcnt_libhb.diff

public diff v1 · immutable
·published 2007-11-13 01:23 UTC
rendered paste body
Index: libhb/hb.c===================================================================--- libhb/hb.c	(revision 1055)+++ libhb/hb.c	(working copy)@@ -692,11 +692,14 @@ }  /**- * Adds a job to the job list.+ * Allocates and returns a copy of the job. The copy will have a reference count of 1.+ * The caller is responsible for calling hb_job_dereference when the copy is no longer+ * needed.  * @param h Handle to hb_handle_t.  * @param job Handle to hb_job_t.+ * @returns Handle to hb_job_t of the copy.  */-void hb_add( hb_handle_t * h, hb_job_t * job )+hb_job_t * hb_job_copy( hb_job_t * job ) {     hb_job_t      * job_copy;     hb_title_t    * title,    * title_copy;@@ -903,8 +906,8 @@     title_copy->job = job_copy;     job_copy->title = title_copy;     job_copy->file  = strdup( job->file );-    job_copy->h     = h;-    job_copy->pause = h->pause_lock;+    job_copy->h     = NULL;+    job_copy->pause = NULL;      /* Copy the job filter list */     if( job->filters )@@ -919,10 +922,32 @@         }             }     +    job_copy->reference_count = 1;++    return( job_copy );+}++/**+ * Adds a copy of a job to the job list.+ * @param h Handle to hb_handle_t.+ * @param job Handle to hb_job_t.+ * @returns Handle to hb_job_t of the copied job.+ */+hb_job_t * hb_add( hb_handle_t * h, hb_job_t * job )+{+    hb_job_t      * job_copy;++    job_copy = hb_job_copy ( job );+        +    job_copy->h     = h;+    job_copy->pause = h->pause_lock;+     /* Add the job to the list */     hb_list_add( h->jobs, job_copy );     h->job_count = hb_count(h);     h->job_count_permanent++;++    return( job_copy ); }  /**@@ -939,6 +964,7 @@         h->job_count_permanent--;      /* XXX free everything XXX */+    hb_job_dereference( job ); }  /**@@ -1207,3 +1233,31 @@     hb_unlock( h->state_lock );     hb_unlock( h->pause_lock ); }++/*+ * Register an interest in referencing this job, it won't be deleted+ * until this party deregisters its interest in it.+ */+void hb_job_reference( const hb_job_t * job_copy )+{+    hb_job_t * job = (hb_job_t * )job_copy;++    job->reference_count++;+}++void hb_job_dereference( const hb_job_t * job_copy )+{+    hb_job_t * job = (hb_job_t * )job_copy;++    job->reference_count--;++    if( job->reference_count <= 0 )+    {+        hb_log( "Freeing job 0x%x", job );++// travistex has moved this hb_title_close call from do_job to here.+        hb_title_close( &job->title );++        free( job );+    }+}Index: libhb/hb.h===================================================================--- libhb/hb.h	(revision 1055)+++ libhb/hb.h	(working copy)@@ -84,7 +84,8 @@ int           hb_count( hb_handle_t * ); hb_job_t *    hb_job( hb_handle_t *, int ); hb_job_t *    hb_current_job( hb_handle_t * h );-void          hb_add( hb_handle_t *, hb_job_t * );+hb_job_t *    hb_job_copy( hb_job_t * job );+hb_job_t *    hb_add( hb_handle_t *, hb_job_t * ); void          hb_rem( hb_handle_t *, hb_job_t * );  void          hb_start( hb_handle_t * );@@ -105,6 +106,9 @@    Aborts all current jobs if any, frees memory. */ void          hb_close( hb_handle_t ** ); +void hb_job_reference( const hb_job_t * job_copy );+void hb_job_dereference( const hb_job_t * job_copy );+ #ifdef __cplusplus } #endifIndex: libhb/work.c===================================================================--- libhb/work.c	(revision 1055)+++ libhb/work.c	(working copy)@@ -723,8 +723,11 @@      hb_buffer_pool_free(); -    hb_title_close( &job->title );-    free( job );+// travistex is requesting that all code to dealloc a job be moved to hb_job_dereference+// so that all data in the job can continue to be referenced until the job is really+// deallocated. I don't know if any of the other code above falls in this same category.+//    hb_title_close( &job->title );+    hb_job_dereference( job ); }  /**Index: libhb/common.h===================================================================--- libhb/common.h	(revision 1055)+++ libhb/common.h	(working copy)@@ -105,6 +105,12 @@  *****************************************************************************/ struct hb_job_s {+    /*+     * Number of folks interested in this job, only free when equal to+     * 0.+     */+    int reference_count;+     /* ID assigned by UI so it can groups job passes together */     int             sequence_id;