aboutsummaryrefslogtreecommitdiffstats
path: root/compat
diff options
context:
space:
mode:
authorKO Myung-Hun <komh78@gmail.com>2016-02-15 00:20:34 +0900
committerMichael Niedermayer <michael@niedermayer.cc>2016-02-14 19:17:36 +0100
commit6bf5e7d3e7d8a7a3746f76e0f1fffb9bb63c02ae (patch)
tree88ae9245be527b8bfc98b60071f50b78f979f75e /compat
parent22a4046d66f7f60eb771c5fe7d2a9b42989d420c (diff)
downloadffmpeg-6bf5e7d3e7d8a7a3746f76e0f1fffb9bb63c02ae.tar.gz
compat/os2threads: support the return value of joined thread
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'compat')
-rw-r--r--compat/os2threads.h39
1 files changed, 18 insertions, 21 deletions
diff --git a/compat/os2threads.h b/compat/os2threads.h
index 12cb7b0dab..3b289dfa26 100644
--- a/compat/os2threads.h
+++ b/compat/os2threads.h
@@ -35,9 +35,15 @@
#include <sys/builtin.h>
#include <sys/fmutex.h>
-#include "libavutil/mem.h"
+#include "libavutil/attributes.h"
+
+typedef struct {
+ TID tid;
+ void *(*start_routine)(void *);
+ void *arg;
+ void *result;
+} pthread_t;
-typedef TID pthread_t;
typedef void pthread_attr_t;
typedef HMTX pthread_mutex_t;
@@ -58,39 +64,30 @@ typedef struct {
#define PTHREAD_ONCE_INIT {0, _FMUTEX_INITIALIZER}
-struct thread_arg {
- void *(*start_routine)(void *);
- void *arg;
-};
-
static void thread_entry(void *arg)
{
- struct thread_arg *thread_arg = arg;
-
- thread_arg->start_routine(thread_arg->arg);
+ pthread_t *thread = arg;
- av_free(thread_arg);
+ thread->result = thread->start_routine(thread->arg);
}
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg)
{
- struct thread_arg *thread_arg;
-
- thread_arg = av_mallocz(sizeof(struct thread_arg));
- if (!thread_arg)
- return ENOMEM;
+ thread->start_routine = start_routine;
+ thread->arg = arg;
+ thread->result = NULL;
- thread_arg->start_routine = start_routine;
- thread_arg->arg = arg;
-
- *thread = _beginthread(thread_entry, NULL, 256 * 1024, thread_arg);
+ thread->tid = _beginthread(thread_entry, NULL, 1024 * 1024, thread);
return 0;
}
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
{
- DosWaitThread((PTID)&thread, DCWW_WAIT);
+ DosWaitThread(&thread.tid, DCWW_WAIT);
+
+ if (value_ptr)
+ *value_ptr = thread.result;
return 0;
}