summaryrefslogtreecommitdiff
path: root/vp8/encoder/ethreading.c
diff options
context:
space:
mode:
authorScott LaVarnway <slavarnway@google.com>2012-08-14 12:00:23 -0700
committerScott LaVarnway <slavarnway@google.com>2012-08-14 12:00:23 -0700
commitd1b6fa41615611f24fa98e896ed94df91f6c6e1e (patch)
tree5c3c5f7193a5d2ecc19d0478eac8b34e83a279de /vp8/encoder/ethreading.c
parentff61cbc5105c16d48ffd291cd85a031cbce36be9 (diff)
downloadlibvpx-d1b6fa41615611f24fa98e896ed94df91f6c6e1e.tar
libvpx-d1b6fa41615611f24fa98e896ed94df91f6c6e1e.tar.gz
libvpx-d1b6fa41615611f24fa98e896ed94df91f6c6e1e.tar.bz2
libvpx-d1b6fa41615611f24fa98e896ed94df91f6c6e1e.zip
Added error checking to vp8cx_create_encoder_threads()
Added checks for pthread_create() errors. Change-Id: Ie198ef5c14314fe252d2e02f7fe5bfacc7e16377
Diffstat (limited to 'vp8/encoder/ethreading.c')
-rw-r--r--vp8/encoder/ethreading.c70
1 files changed, 61 insertions, 9 deletions
diff --git a/vp8/encoder/ethreading.c b/vp8/encoder/ethreading.c
index e0bb1b09f..964d8b325 100644
--- a/vp8/encoder/ethreading.c
+++ b/vp8/encoder/ethreading.c
@@ -484,7 +484,7 @@ void vp8cx_init_mbrthread_data(VP8_COMP *cpi,
}
}
-void vp8cx_create_encoder_threads(VP8_COMP *cpi)
+int vp8cx_create_encoder_threads(VP8_COMP *cpi)
{
const VP8_COMMON * cm = &cpi->common;
@@ -496,6 +496,7 @@ void vp8cx_create_encoder_threads(VP8_COMP *cpi)
{
int ithread;
int th_count = cpi->oxcf.multi_threaded - 1;
+ int rc = 0;
/* don't allocate more threads than cores available */
if (cpi->oxcf.multi_threaded > cm->processor_core_count)
@@ -509,11 +510,14 @@ void vp8cx_create_encoder_threads(VP8_COMP *cpi)
}
if(th_count == 0)
- return;
-
- CHECK_MEM_ERROR(cpi->h_encoding_thread, vpx_malloc(sizeof(pthread_t) * th_count));
- CHECK_MEM_ERROR(cpi->h_event_start_encoding, vpx_malloc(sizeof(sem_t) * th_count));
- CHECK_MEM_ERROR(cpi->mb_row_ei, vpx_memalign(32, sizeof(MB_ROW_COMP) * th_count));
+ return 0;
+
+ CHECK_MEM_ERROR(cpi->h_encoding_thread,
+ vpx_malloc(sizeof(pthread_t) * th_count));
+ CHECK_MEM_ERROR(cpi->h_event_start_encoding,
+ vpx_malloc(sizeof(sem_t) * th_count));
+ CHECK_MEM_ERROR(cpi->mb_row_ei,
+ vpx_memalign(32, sizeof(MB_ROW_COMP) * th_count));
vpx_memset(cpi->mb_row_ei, 0, sizeof(MB_ROW_COMP) * th_count);
CHECK_MEM_ERROR(cpi->en_thread_data,
vpx_malloc(sizeof(ENCODETHREAD_DATA) * th_count));
@@ -542,9 +546,33 @@ void vp8cx_create_encoder_threads(VP8_COMP *cpi)
ethd->ptr1 = (void *)cpi;
ethd->ptr2 = (void *)&cpi->mb_row_ei[ithread];
- pthread_create(&cpi->h_encoding_thread[ithread], 0, thread_encoding_proc, ethd);
+ rc = pthread_create(&cpi->h_encoding_thread[ithread], 0,
+ thread_encoding_proc, ethd);
+ if(rc)
+ break;
+ }
+
+ if(rc)
+ {
+ /* shutdown other threads */
+ cpi->b_multi_threaded = 0;
+ for(--ithread; ithread >= 0; ithread--)
+ {
+ pthread_join(cpi->h_encoding_thread[ithread], 0);
+ sem_destroy(&cpi->h_event_start_encoding[ithread]);
+ }
+ sem_destroy(&cpi->h_event_end_encoding);
+
+ /* free thread related resources */
+ vpx_free(cpi->h_event_start_encoding);
+ vpx_free(cpi->h_encoding_thread);
+ vpx_free(cpi->mb_row_ei);
+ vpx_free(cpi->en_thread_data);
+
+ return -1;
}
+
{
LPFTHREAD_DATA * lpfthd = &cpi->lpf_thread_data;
@@ -552,10 +580,34 @@ void vp8cx_create_encoder_threads(VP8_COMP *cpi)
sem_init(&cpi->h_event_end_lpf, 0, 0);
lpfthd->ptr1 = (void *)cpi;
- pthread_create(&cpi->h_filter_thread, 0, thread_loopfilter, lpfthd);
+ rc = pthread_create(&cpi->h_filter_thread, 0, thread_loopfilter,
+ lpfthd);
+
+ if(rc)
+ {
+ /* shutdown other threads */
+ cpi->b_multi_threaded = 0;
+ for(--ithread; ithread >= 0; ithread--)
+ {
+ sem_post(&cpi->h_event_start_encoding[ithread]);
+ pthread_join(cpi->h_encoding_thread[ithread], 0);
+ sem_destroy(&cpi->h_event_start_encoding[ithread]);
+ }
+ sem_destroy(&cpi->h_event_end_encoding);
+ sem_destroy(&cpi->h_event_end_lpf);
+ sem_destroy(&cpi->h_event_start_lpf);
+
+ /* free thread related resources */
+ vpx_free(cpi->h_event_start_encoding);
+ vpx_free(cpi->h_encoding_thread);
+ vpx_free(cpi->mb_row_ei);
+ vpx_free(cpi->en_thread_data);
+
+ return -2;
+ }
}
}
-
+ return 0;
}
void vp8cx_remove_encoder_threads(VP8_COMP *cpi)