summaryrefslogtreecommitdiff
path: root/compat/w32pthreads.h
diff options
context:
space:
mode:
Diffstat (limited to 'compat/w32pthreads.h')
-rw-r--r--compat/w32pthreads.h85
1 files changed, 51 insertions, 34 deletions
diff --git a/compat/w32pthreads.h b/compat/w32pthreads.h
index f38f767d8f..eeead6051f 100644
--- a/compat/w32pthreads.h
+++ b/compat/w32pthreads.h
@@ -4,20 +4,20 @@
* Authors: Steven Walters <kemuri9@gmail.com>
* Pegasys Inc. <http://www.pegasys-inc.com>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -26,8 +26,8 @@
* w32threads to pthreads wrapper
*/
-#ifndef LIBAV_COMPAT_W32PTHREADS_H
-#define LIBAV_COMPAT_W32PTHREADS_H
+#ifndef COMPAT_W32PTHREADS_H
+#define COMPAT_W32PTHREADS_H
/* Build up a pthread-like API using underlying Windows API. Have only static
* methods so as to not conflict with a potentially linked in pthread-win32
@@ -45,6 +45,7 @@
#endif
#include "libavutil/attributes.h"
+#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/mem.h"
@@ -76,7 +77,7 @@ typedef struct pthread_cond_t {
static av_unused unsigned __stdcall attribute_align_arg win32thread_worker(void *arg)
{
- pthread_t *h = arg;
+ pthread_t *h = (pthread_t*)arg;
h->ret = h->func(h->arg);
return 0;
}
@@ -86,19 +87,29 @@ static av_unused int pthread_create(pthread_t *thread, const void *unused_attr,
{
thread->func = start_routine;
thread->arg = arg;
+#if HAVE_WINRT
+ thread->handle = (void*)CreateThread(NULL, 0, win32thread_worker, thread,
+ 0, NULL);
+#else
thread->handle = (void*)_beginthreadex(NULL, 0, win32thread_worker, thread,
0, NULL);
+#endif
return !thread->handle;
}
-static av_unused void pthread_join(pthread_t thread, void **value_ptr)
+static av_unused int pthread_join(pthread_t thread, void **value_ptr)
{
DWORD ret = WaitForSingleObject(thread.handle, INFINITE);
- if (ret != WAIT_OBJECT_0)
- return;
+ if (ret != WAIT_OBJECT_0) {
+ if (ret == WAIT_ABANDONED)
+ return EINVAL;
+ else
+ return EDEADLK;
+ }
if (value_ptr)
*value_ptr = thread.ret;
CloseHandle(thread.handle);
+ return 0;
}
static inline int pthread_mutex_init(pthread_mutex_t *m, void* attr)
@@ -123,7 +134,6 @@ static inline int pthread_mutex_unlock(pthread_mutex_t *m)
}
#if _WIN32_WINNT >= 0x0600
-
typedef INIT_ONCE pthread_once_t;
#define PTHREAD_ONCE_INIT INIT_ONCE_STATIC_INIT
@@ -137,20 +147,22 @@ static av_unused int pthread_once(pthread_once_t *once_control, void (*init_rout
return 0;
}
-static inline void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
+static inline int pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
{
InitializeConditionVariable(cond);
+ return 0;
}
/* native condition variables do not destroy */
-static inline void pthread_cond_destroy(pthread_cond_t *cond)
+static inline int pthread_cond_destroy(pthread_cond_t *cond)
{
- return;
+ return 0;
}
-static inline void pthread_cond_broadcast(pthread_cond_t *cond)
+static inline int pthread_cond_broadcast(pthread_cond_t *cond)
{
WakeAllConditionVariable(cond);
+ return 0;
}
static inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
@@ -159,9 +171,10 @@ static inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex
return 0;
}
-static inline void pthread_cond_signal(pthread_cond_t *cond)
+static inline int pthread_cond_signal(pthread_cond_t *cond)
{
WakeConditionVariable(cond);
+ return 0;
}
#else // _WIN32_WINNT < 0x0600
@@ -245,7 +258,7 @@ static void (WINAPI *cond_signal)(pthread_cond_t *cond);
static BOOL (WINAPI *cond_wait)(pthread_cond_t *cond, pthread_mutex_t *mutex,
DWORD milliseconds);
-static av_unused void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
+static av_unused int pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)
{
win32_cond_t *win32_cond = NULL;
@@ -253,31 +266,32 @@ static av_unused void pthread_cond_init(pthread_cond_t *cond, const void *unused
if (cond_init) {
cond_init(cond);
- return;
+ return 0;
}
/* non native condition variables */
- win32_cond = av_mallocz(sizeof(win32_cond_t));
+ win32_cond = (win32_cond_t*)av_mallocz(sizeof(win32_cond_t));
if (!win32_cond)
- return;
+ return ENOMEM;
cond->Ptr = win32_cond;
win32_cond->semaphore = CreateSemaphore(NULL, 0, 0x7fffffff, NULL);
if (!win32_cond->semaphore)
- return;
+ return ENOMEM;
win32_cond->waiters_done = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!win32_cond->waiters_done)
- return;
+ return ENOMEM;
pthread_mutex_init(&win32_cond->mtx_waiter_count, NULL);
pthread_mutex_init(&win32_cond->mtx_broadcast, NULL);
+ return 0;
}
-static av_unused void pthread_cond_destroy(pthread_cond_t *cond)
+static av_unused int pthread_cond_destroy(pthread_cond_t *cond)
{
- win32_cond_t *win32_cond = cond->Ptr;
+ win32_cond_t *win32_cond = (win32_cond_t*)cond->Ptr;
/* native condition variables do not destroy */
if (cond_init)
- return;
+ return 0;
/* non native condition variables */
CloseHandle(win32_cond->semaphore);
@@ -286,16 +300,17 @@ static av_unused void pthread_cond_destroy(pthread_cond_t *cond)
pthread_mutex_destroy(&win32_cond->mtx_broadcast);
av_freep(&win32_cond);
cond->Ptr = NULL;
+ return 0;
}
-static av_unused void pthread_cond_broadcast(pthread_cond_t *cond)
+static av_unused int pthread_cond_broadcast(pthread_cond_t *cond)
{
- win32_cond_t *win32_cond = cond->Ptr;
+ win32_cond_t *win32_cond = (win32_cond_t*)cond->Ptr;
int have_waiter;
if (cond_broadcast) {
cond_broadcast(cond);
- return;
+ return 0;
}
/* non native condition variables */
@@ -317,11 +332,12 @@ static av_unused void pthread_cond_broadcast(pthread_cond_t *cond)
} else
pthread_mutex_unlock(&win32_cond->mtx_waiter_count);
pthread_mutex_unlock(&win32_cond->mtx_broadcast);
+ return 0;
}
static av_unused int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
{
- win32_cond_t *win32_cond = cond->Ptr;
+ win32_cond_t *win32_cond = (win32_cond_t*)cond->Ptr;
int last_waiter;
if (cond_wait) {
cond_wait(cond, mutex, INFINITE);
@@ -351,13 +367,13 @@ static av_unused int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mu
return pthread_mutex_lock(mutex);
}
-static av_unused void pthread_cond_signal(pthread_cond_t *cond)
+static av_unused int pthread_cond_signal(pthread_cond_t *cond)
{
- win32_cond_t *win32_cond = cond->Ptr;
+ win32_cond_t *win32_cond = (win32_cond_t*)cond->Ptr;
int have_waiter;
if (cond_signal) {
cond_signal(cond);
- return;
+ return 0;
}
pthread_mutex_lock(&win32_cond->mtx_broadcast);
@@ -374,13 +390,14 @@ static av_unused void pthread_cond_signal(pthread_cond_t *cond)
}
pthread_mutex_unlock(&win32_cond->mtx_broadcast);
+ return 0;
}
#endif
static av_unused void w32thread_init(void)
{
#if _WIN32_WINNT < 0x0600
- HANDLE kernel_dll = GetModuleHandle(TEXT("kernel32.dll"));
+ HMODULE kernel_dll = GetModuleHandle(TEXT("kernel32.dll"));
/* if one is available, then they should all be available */
cond_init = (void (WINAPI*)(pthread_cond_t *))
GetProcAddress(kernel_dll, "InitializeConditionVariable");
@@ -398,4 +415,4 @@ static av_unused void w32thread_init(void)
}
-#endif /* LIBAV_COMPAT_W32PTHREADS_H */
+#endif /* COMPAT_W32PTHREADS_H */