* 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
*/
* w32threads to pthreads wrapper
*/
-#ifndef LIBAV_COMPAT_W32PTHREADS_H
-#define LIBAV_COMPAT_W32PTHREADS_H
+#ifndef FFMPEG_COMPAT_W32PTHREADS_H
+#define FFMPEG_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
#include <windows.h>
#include <process.h>
- /* MinGW requires the intrinsics header for the pthread_once fallback code */
#if _WIN32_WINNT < 0x0600 && defined(__MINGW32__)
- #include <intrin.h>
+ #undef MemoryBarrier
+ #define MemoryBarrier __sync_synchronize
#endif
#include "libavutil/attributes.h"
+#include "libavutil/common.h"
#include "libavutil/internal.h"
#include "libavutil/mem.h"
{
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)
}
#if _WIN32_WINNT >= 0x0600
-
typedef INIT_ONCE pthread_once_t;
#define PTHREAD_ONCE_INIT INIT_ONCE_STATIC_INIT
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)
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
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;
if (cond_init) {
cond_init(cond);
- return;
+ return 0;
}
/* non native condition variables */
win32_cond = 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;
/* native condition variables do not destroy */
if (cond_init)
- return;
+ return 0;
/* non native condition variables */
CloseHandle(win32_cond->semaphore);
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;
int have_waiter;
if (cond_broadcast) {
cond_broadcast(cond);
- return;
+ return 0;
}
/* non native condition variables */
} 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)
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;
int have_waiter;
if (cond_signal) {
cond_signal(cond);
- return;
+ return 0;
}
pthread_mutex_lock(&win32_cond->mtx_broadcast);
}
pthread_mutex_unlock(&win32_cond->mtx_broadcast);
+ return 0;
}
#endif
}
-#endif /* LIBAV_COMPAT_W32PTHREADS_H */
+#endif /* FFMPEG_COMPAT_W32PTHREADS_H */