ref: 66241b95796902e0d86ab934f5fe3d778780c8b6
parent: 4b0e78bfdaccc969fa7d524bd635e403dad68650
parent: 948a1f51d01f531e3e2b5d7e794d5f09c0b07cd5
author: James Zern <jzern@google.com>
date: Thu Sep 8 23:08:18 EDT 2016
Merge "vp8: Remove TSAN warning around end of encode."
--- a/vp8/encoder/encodeframe.c
+++ b/vp8/encoder/encodeframe.c
@@ -788,14 +788,11 @@
xd->mode_info_stride * cpi->encoding_thread_count;
x->partition_info += xd->mode_info_stride * cpi->encoding_thread_count;
x->gf_active_ptr += cm->mb_cols * cpi->encoding_thread_count;
-
- if (mb_row == cm->mb_rows - 1) {
- sem_post(&cpi->h_event_end_encoding); /* signal frame encoding end */
- }
}
-
- sem_wait(
- &cpi->h_event_end_encoding); /* wait for other threads to finish */
+ /* Wait for all the threads to finish. */
+ for (i = 0; i < cpi->encoding_thread_count; ++i) {
+ sem_wait(&cpi->h_event_end_encoding[i]);
+ }
for (mb_row = 0; mb_row < cm->mb_rows; ++mb_row) {
cpi->tok_count += (unsigned int)(cpi->tplist[mb_row].stop -
--- a/vp8/encoder/ethreading.c
+++ b/vp8/encoder/ethreading.c
@@ -301,11 +301,9 @@
xd->mode_info_stride * cpi->encoding_thread_count;
x->partition_info += xd->mode_info_stride * cpi->encoding_thread_count;
x->gf_active_ptr += cm->mb_cols * cpi->encoding_thread_count;
-
- if (mb_row == cm->mb_rows - 1) {
- sem_post(&cpi->h_event_end_encoding); /* signal frame encoding end */
- }
}
+ /* Signal that this thread has completed processing its rows. */
+ sem_post(&cpi->h_event_end_encoding[ithread]);
}
}
@@ -516,6 +514,8 @@
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->h_event_end_encoding,
+ vpx_malloc(sizeof(sem_t) * th_count));
CHECK_MEM_ERROR(cpi->mb_row_ei,
vpx_memalign(32, sizeof(MB_ROW_COMP) * th_count));
memset(cpi->mb_row_ei, 0, sizeof(MB_ROW_COMP) * th_count);
@@ -522,8 +522,6 @@
CHECK_MEM_ERROR(cpi->en_thread_data,
vpx_malloc(sizeof(ENCODETHREAD_DATA) * th_count));
- sem_init(&cpi->h_event_end_encoding, 0, 0);
-
cpi->b_multi_threaded = 1;
cpi->encoding_thread_count = th_count;
@@ -540,6 +538,7 @@
vp8_setup_block_dptrs(&cpi->mb_row_ei[ithread].mb.e_mbd);
sem_init(&cpi->h_event_start_encoding[ithread], 0, 0);
+ sem_init(&cpi->h_event_end_encoding[ithread], 0, 0);
ethd->ithread = ithread;
ethd->ptr1 = (void *)cpi;
@@ -556,11 +555,12 @@
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[ithread]);
}
- sem_destroy(&cpi->h_event_end_encoding);
/* free thread related resources */
vpx_free(cpi->h_event_start_encoding);
+ vpx_free(cpi->h_event_end_encoding);
vpx_free(cpi->h_encoding_thread);
vpx_free(cpi->mb_row_ei);
vpx_free(cpi->en_thread_data);
@@ -582,15 +582,17 @@
cpi->b_multi_threaded = 0;
for (--ithread; ithread >= 0; ithread--) {
sem_post(&cpi->h_event_start_encoding[ithread]);
+ sem_post(&cpi->h_event_end_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[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_event_end_encoding);
vpx_free(cpi->h_encoding_thread);
vpx_free(cpi->mb_row_ei);
vpx_free(cpi->en_thread_data);
@@ -611,9 +613,12 @@
for (i = 0; i < cpi->encoding_thread_count; ++i) {
sem_post(&cpi->h_event_start_encoding[i]);
+ sem_post(&cpi->h_event_end_encoding[i]);
+
pthread_join(cpi->h_encoding_thread[i], 0);
sem_destroy(&cpi->h_event_start_encoding[i]);
+ sem_destroy(&cpi->h_event_end_encoding[i]);
}
sem_post(&cpi->h_event_start_lpf);
@@ -620,12 +625,12 @@
pthread_join(cpi->h_filter_thread, 0);
}
- 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_event_end_encoding);
vpx_free(cpi->h_encoding_thread);
vpx_free(cpi->mb_row_ei);
vpx_free(cpi->en_thread_data);
--- a/vp8/encoder/onyx_int.h
+++ b/vp8/encoder/onyx_int.h
@@ -518,7 +518,7 @@
/* events */
sem_t *h_event_start_encoding;
- sem_t h_event_end_encoding;
+ sem_t *h_event_end_encoding;
sem_t h_event_start_lpf;
sem_t h_event_end_lpf;
#endif