Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
KO Myung-Hun authored on 2016/02/15 00:20:34... | ... |
@@ -35,9 +35,15 @@ |
35 | 35 |
#include <sys/builtin.h> |
36 | 36 |
#include <sys/fmutex.h> |
37 | 37 |
|
38 |
-#include "libavutil/mem.h" |
|
38 |
+#include "libavutil/attributes.h" |
|
39 |
+ |
|
40 |
+typedef struct { |
|
41 |
+ TID tid; |
|
42 |
+ void *(*start_routine)(void *); |
|
43 |
+ void *arg; |
|
44 |
+ void *result; |
|
45 |
+} pthread_t; |
|
39 | 46 |
|
40 |
-typedef TID pthread_t; |
|
41 | 47 |
typedef void pthread_attr_t; |
42 | 48 |
|
43 | 49 |
typedef HMTX pthread_mutex_t; |
... | ... |
@@ -58,39 +64,30 @@ typedef struct { |
58 | 58 |
|
59 | 59 |
#define PTHREAD_ONCE_INIT {0, _FMUTEX_INITIALIZER} |
60 | 60 |
|
61 |
-struct thread_arg { |
|
62 |
- void *(*start_routine)(void *); |
|
63 |
- void *arg; |
|
64 |
-}; |
|
65 |
- |
|
66 | 61 |
static void thread_entry(void *arg) |
67 | 62 |
{ |
68 |
- struct thread_arg *thread_arg = arg; |
|
69 |
- |
|
70 |
- thread_arg->start_routine(thread_arg->arg); |
|
63 |
+ pthread_t *thread = arg; |
|
71 | 64 |
|
72 |
- av_free(thread_arg); |
|
65 |
+ thread->result = thread->start_routine(thread->arg); |
|
73 | 66 |
} |
74 | 67 |
|
75 | 68 |
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg) |
76 | 69 |
{ |
77 |
- struct thread_arg *thread_arg; |
|
78 |
- |
|
79 |
- thread_arg = av_mallocz(sizeof(struct thread_arg)); |
|
80 |
- if (!thread_arg) |
|
81 |
- return ENOMEM; |
|
70 |
+ thread->start_routine = start_routine; |
|
71 |
+ thread->arg = arg; |
|
72 |
+ thread->result = NULL; |
|
82 | 73 |
|
83 |
- thread_arg->start_routine = start_routine; |
|
84 |
- thread_arg->arg = arg; |
|
85 |
- |
|
86 |
- *thread = _beginthread(thread_entry, NULL, 256 * 1024, thread_arg); |
|
74 |
+ thread->tid = _beginthread(thread_entry, NULL, 1024 * 1024, thread); |
|
87 | 75 |
|
88 | 76 |
return 0; |
89 | 77 |
} |
90 | 78 |
|
91 | 79 |
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr) |
92 | 80 |
{ |
93 |
- DosWaitThread((PTID)&thread, DCWW_WAIT); |
|
81 |
+ DosWaitThread(&thread.tid, DCWW_WAIT); |
|
82 |
+ |
|
83 |
+ if (value_ptr) |
|
84 |
+ *value_ptr = thread.result; |
|
94 | 85 |
|
95 | 86 |
return 0; |
96 | 87 |
} |