All pastes #744161 Raw Edit

HB ref count

public diff v1 · immutable
·published 2007-10-21 04:07 UTC
rendered paste body
Index: libhb/hb.c===================================================================--- libhb/hb.c	(revision 1033)+++ libhb/hb.c	(working copy)@@ -696,7 +696,7 @@  * @param h Handle to hb_handle_t.  * @param job Handle to hb_job_t.  */-void hb_add( hb_handle_t * h, hb_job_t * job )+const hb_job_t * hb_add( hb_handle_t * h, hb_job_t * job ) {     hb_job_t      * job_copy;     hb_title_t    * title,    * title_copy;@@ -923,6 +923,10 @@     hb_list_add( h->jobs, job_copy );     h->job_count = hb_count(h);     h->job_count_permanent++;++    hb_job_reference( job_copy );++    return( job_copy ); }  /**@@ -1207,3 +1211,27 @@     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 );+        free( job );+    }+}Index: libhb/hb.h===================================================================--- libhb/hb.h	(revision 1033)+++ libhb/hb.h	(working copy)@@ -84,7 +84,7 @@ 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 * );+const 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 +105,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 1033)+++ libhb/work.c	(working copy)@@ -703,7 +703,7 @@     hb_buffer_pool_free();      hb_title_close( &job->title );-    free( job );+    hb_job_dereference( job ); }  /**Index: libhb/common.h===================================================================--- libhb/common.h	(revision 1033)+++ 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;