[x264-devel] Fix pthread_join emulation on win32 and BeOS

Anton Mitrofanov git at videolan.org
Wed Jan 9 19:32:22 CET 2013


x264 | branch: master | Anton Mitrofanov <BugMaster at narod.ru> | Fri Nov 23 18:26:53 2012 +0400| [55b5162d7ad9a70e2b6ae5ba3f743a35c2135aaf] | committer: Jason Garrett-Glaser

Fix pthread_join emulation on win32 and BeOS
Doesn't actually affect x264, but it's more correct.

> http://git.videolan.org/gitweb.cgi/x264.git/?a=commit;h=55b5162d7ad9a70e2b6ae5ba3f743a35c2135aaf
---

 common/osdep.h       |    2 +-
 common/threadpool.c  |    3 ++-
 common/win32thread.c |    6 ++++--
 common/win32thread.h |    1 +
 encoder/lookahead.c  |    3 ++-
 5 files changed, 10 insertions(+), 5 deletions(-)

diff --git a/common/osdep.h b/common/osdep.h
index 4d588ec..d13d68a 100644
--- a/common/osdep.h
+++ b/common/osdep.h
@@ -149,7 +149,7 @@ static inline int x264_pthread_create( x264_pthread_t *t, void *a, void *(*f)(vo
      return 0;
 }
 #define x264_pthread_join(t,s)       { long tmp; \
-                                       wait_for_thread(t,(s)?(long*)(*(s)):&tmp); }
+                                       wait_for_thread(t,(s)?(long*)(s):&tmp); }
 
 #elif HAVE_POSIXTHREAD
 #include <pthread.h>
diff --git a/common/threadpool.c b/common/threadpool.c
index a11bf9d..9be6c41 100644
--- a/common/threadpool.c
+++ b/common/threadpool.c
@@ -47,7 +47,7 @@ struct x264_threadpool_t
     x264_sync_frame_list_t done;   /* list of jobs that have finished processing */
 };
 
-static void x264_threadpool_thread( x264_threadpool_t *pool )
+static void *x264_threadpool_thread( x264_threadpool_t *pool )
 {
     if( pool->init_func )
         pool->init_func( pool->init_arg );
@@ -69,6 +69,7 @@ static void x264_threadpool_thread( x264_threadpool_t *pool )
         job->ret = (void*)x264_stack_align( job->func, job->arg ); /* execute the function */
         x264_sync_frame_list_push( &pool->done, (void*)job );
     }
+    return NULL;
 }
 
 int x264_threadpool_init( x264_threadpool_t **p_pool, int threads,
diff --git a/common/win32thread.c b/common/win32thread.c
index a81cd6c..405c5b6 100644
--- a/common/win32thread.c
+++ b/common/win32thread.c
@@ -62,7 +62,7 @@ static x264_win32thread_control_t thread_control;
 static unsigned __stdcall x264_win32thread_worker( void *arg )
 {
     x264_pthread_t *h = arg;
-    h->ret = h->func( h->arg );
+    *h->p_ret = h->func( h->arg );
     return 0;
 }
 
@@ -71,6 +71,8 @@ int x264_pthread_create( x264_pthread_t *thread, const x264_pthread_attr_t *attr
 {
     thread->func   = start_routine;
     thread->arg    = arg;
+    thread->p_ret  = &thread->ret;
+    thread->ret    = NULL;
     thread->handle = (void*)_beginthreadex( NULL, 0, x264_win32thread_worker, thread, 0, NULL );
     return !thread->handle;
 }
@@ -81,7 +83,7 @@ int x264_pthread_join( x264_pthread_t thread, void **value_ptr )
     if( ret != WAIT_OBJECT_0 )
         return -1;
     if( value_ptr )
-        *value_ptr = thread.ret;
+        *value_ptr = *thread.p_ret;
     CloseHandle( thread.handle );
     return 0;
 }
diff --git a/common/win32thread.h b/common/win32thread.h
index d6370a7..c8f4476 100644
--- a/common/win32thread.h
+++ b/common/win32thread.h
@@ -36,6 +36,7 @@ typedef struct
     void *handle;
     void *(*func)( void* arg );
     void *arg;
+    void **p_ret;
     void *ret;
 } x264_pthread_t;
 #define x264_pthread_attr_t int
diff --git a/encoder/lookahead.c b/encoder/lookahead.c
index fda59ab..c4169d3 100644
--- a/encoder/lookahead.c
+++ b/encoder/lookahead.c
@@ -86,7 +86,7 @@ static void x264_lookahead_slicetype_decide( x264_t *h )
     x264_pthread_mutex_unlock( &h->lookahead->ofbuf.mutex );
 }
 
-static void x264_lookahead_thread( x264_t *h )
+static void *x264_lookahead_thread( x264_t *h )
 {
     int shift;
 #if HAVE_MMX
@@ -123,6 +123,7 @@ static void x264_lookahead_thread( x264_t *h )
     h->lookahead->b_thread_active = 0;
     x264_pthread_cond_broadcast( &h->lookahead->ofbuf.cv_fill );
     x264_pthread_mutex_unlock( &h->lookahead->ofbuf.mutex );
+    return NULL;
 }
 #endif
 



More information about the x264-devel mailing list