Commit 6bf5e7d3 authored by KO Myung-Hun's avatar KO Myung-Hun Committed by Michael Niedermayer

compat/os2threads: support the return value of joined thread

Signed-off-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
parent 22a4046d
...@@ -35,9 +35,15 @@ ...@@ -35,9 +35,15 @@
#include <sys/builtin.h> #include <sys/builtin.h>
#include <sys/fmutex.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 void pthread_attr_t;
typedef HMTX pthread_mutex_t; typedef HMTX pthread_mutex_t;
...@@ -58,39 +64,30 @@ typedef struct { ...@@ -58,39 +64,30 @@ typedef struct {
#define PTHREAD_ONCE_INIT {0, _FMUTEX_INITIALIZER} #define PTHREAD_ONCE_INIT {0, _FMUTEX_INITIALIZER}
struct thread_arg {
void *(*start_routine)(void *);
void *arg;
};
static void thread_entry(void *arg) static void thread_entry(void *arg)
{ {
struct thread_arg *thread_arg = arg; pthread_t *thread = arg;
thread_arg->start_routine(thread_arg->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) 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->start_routine = start_routine;
thread->arg = arg;
thread_arg = av_mallocz(sizeof(struct thread_arg)); thread->result = NULL;
if (!thread_arg)
return ENOMEM;
thread_arg->start_routine = start_routine; thread->tid = _beginthread(thread_entry, NULL, 1024 * 1024, thread);
thread_arg->arg = arg;
*thread = _beginthread(thread_entry, NULL, 256 * 1024, thread_arg);
return 0; return 0;
} }
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr) 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; return 0;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment