mirror of
https://github.com/mpv-player/mpv
synced 2024-12-27 09:32:40 +00:00
build: make pthreads mandatory
pthreads should be available anywhere. Even if not, for environment without threads a pthread wrapper could be provided that can't actually start threads, thus disabling features that require threads. Make pthreads mandatory in order to simplify build dependencies and to reduce ifdeffery. (Admittedly, there wasn't much complexity, but maybe we will use pthreads more in the future, and then it'd become a real bother.)
This commit is contained in:
parent
0a18f3eb9a
commit
0d255f07bf
@ -29,6 +29,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <libavutil/avstring.h>
|
||||
@ -65,16 +66,8 @@
|
||||
#include "osdep/macosx_events.h"
|
||||
#endif
|
||||
|
||||
#if HAVE_PTHREADS
|
||||
#include <pthread.h>
|
||||
#define input_lock(ictx) pthread_mutex_lock(&ictx->mutex)
|
||||
#define input_unlock(ictx) pthread_mutex_unlock(&ictx->mutex)
|
||||
#define input_destroy(ictx) pthread_mutex_destroy(&ictx->mutex)
|
||||
#else
|
||||
#define input_lock(ictx) 0
|
||||
#define input_unlock(ictx) 0
|
||||
#define input_destroy(ictx) 0
|
||||
#endif
|
||||
|
||||
#define MP_MAX_KEY_DOWN 4
|
||||
|
||||
@ -549,9 +542,7 @@ struct cmd_queue {
|
||||
};
|
||||
|
||||
struct input_ctx {
|
||||
#if HAVE_PTHREADS
|
||||
pthread_mutex_t mutex;
|
||||
#endif
|
||||
struct mp_log *log;
|
||||
|
||||
bool using_ar;
|
||||
@ -2299,13 +2290,11 @@ struct input_ctx *mp_input_init(struct mpv_global *global)
|
||||
.wakeup_pipe = {-1, -1},
|
||||
};
|
||||
|
||||
#if HAVE_PTHREADS
|
||||
pthread_mutexattr_t attr;
|
||||
pthread_mutexattr_init(&attr);
|
||||
pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
||||
pthread_mutex_init(&ictx->mutex, &attr);
|
||||
pthread_mutexattr_destroy(&attr);
|
||||
#endif
|
||||
|
||||
// Setup default section, so that it does nothing.
|
||||
mp_input_enable_section(ictx, NULL, MP_INPUT_ALLOW_VO_DRAGGING |
|
||||
@ -2447,7 +2436,7 @@ void mp_input_uninit(struct input_ctx *ictx)
|
||||
}
|
||||
clear_queue(&ictx->cmd_queue);
|
||||
talloc_free(ictx->current_down_cmd);
|
||||
input_destroy(ictx);
|
||||
pthread_mutex_destroy(&ictx->mutex);
|
||||
talloc_free(ictx);
|
||||
}
|
||||
|
||||
|
@ -352,7 +352,6 @@ const m_option_t mp_opts[] = {
|
||||
|
||||
// ------------------------- stream options --------------------
|
||||
|
||||
#if HAVE_STREAM_CACHE
|
||||
OPT_CHOICE_OR_INT("cache", stream_cache_size, 0, 32, 0x7fffffff,
|
||||
({"no", 0},
|
||||
{"auto", -1}),
|
||||
@ -364,7 +363,7 @@ const m_option_t mp_opts[] = {
|
||||
OPT_FLOATRANGE("cache-seek-min", stream_cache_seek_min_percent, 0, 0, 99),
|
||||
OPT_CHOICE_OR_INT("cache-pause", stream_cache_pause, 0,
|
||||
0, 40, ({"no", -1})),
|
||||
#endif /* HAVE_STREAM_CACHE */
|
||||
|
||||
{"cdrom-device", &cdrom_device, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
||||
#if HAVE_DVDREAD
|
||||
{"dvd-device", &dvd_device, CONF_TYPE_STRING, 0, 0, 0, NULL},
|
||||
|
@ -1325,6 +1325,10 @@ else
|
||||
fi
|
||||
echores "$_pthreads"
|
||||
|
||||
if test "$_pthreads" = no ; then
|
||||
die "Unable to find pthreads support."
|
||||
fi
|
||||
|
||||
if test "$_pthreads" = yes ; then
|
||||
|
||||
# Cargo-cult for -lrt, which is needed on not so recent glibc version for
|
||||
|
@ -59,10 +59,7 @@ char *mp_to_utf8(void *talloc_ctx, const wchar_t *s)
|
||||
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#if HAVE_PTHREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include "mpvcore/mp_talloc.h"
|
||||
|
||||
@ -300,12 +297,8 @@ static void init_getenv(void)
|
||||
|
||||
char *mp_getenv(const char *name)
|
||||
{
|
||||
#if HAVE_PTHREADS
|
||||
static pthread_once_t once_init_getenv = PTHREAD_ONCE_INIT;
|
||||
pthread_once(&once_init_getenv, init_getenv);
|
||||
#else
|
||||
init_getenv();
|
||||
#endif
|
||||
// Copied from musl, http://git.musl-libc.org/cgit/musl/tree/COPYRIGHT
|
||||
// Copyright © 2005-2013 Rich Felker, standard MIT license
|
||||
int i;
|
||||
|
@ -809,12 +809,7 @@ static int stream_enable_cache(stream_t **stream, int64_t size, int64_t min,
|
||||
cache->start_pos = orig->start_pos;
|
||||
cache->end_pos = orig->end_pos;
|
||||
|
||||
int res = -1;
|
||||
|
||||
#if HAVE_STREAM_CACHE
|
||||
res = stream_cache_init(cache, orig, size, min, seek_limit);
|
||||
#endif
|
||||
|
||||
int res = stream_cache_init(cache, orig, size, min, seek_limit);
|
||||
if (res <= 0) {
|
||||
cache->uncached_stream = NULL; // don't free original stream
|
||||
free_stream(cache);
|
||||
|
@ -30,7 +30,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <libavcodec/avcodec.h>
|
||||
#include <libavutil/avassert.h>
|
||||
@ -44,15 +44,9 @@
|
||||
#include "lavc.h"
|
||||
#include "video/decode/dec_video.h"
|
||||
|
||||
#if HAVE_PTHREADS
|
||||
#include <pthread.h>
|
||||
static pthread_mutex_t pool_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#define pool_lock() pthread_mutex_lock(&pool_mutex)
|
||||
#define pool_unlock() pthread_mutex_unlock(&pool_mutex)
|
||||
#else
|
||||
#define pool_lock() 0
|
||||
#define pool_unlock() 0
|
||||
#endif
|
||||
|
||||
typedef struct FramePool {
|
||||
struct FrameBuffer *list;
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <libavutil/mem.h>
|
||||
@ -38,15 +39,9 @@
|
||||
|
||||
#include "video/filter/vf.h"
|
||||
|
||||
#if HAVE_PTHREADS
|
||||
#include <pthread.h>
|
||||
static pthread_mutex_t refcount_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#define refcount_lock() pthread_mutex_lock(&refcount_mutex)
|
||||
#define refcount_unlock() pthread_mutex_unlock(&refcount_mutex)
|
||||
#else
|
||||
#define refcount_lock() 0
|
||||
#define refcount_unlock() 0
|
||||
#endif
|
||||
|
||||
struct m_refcount {
|
||||
void *arg;
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdbool.h>
|
||||
#include <pthread.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "talloc.h"
|
||||
@ -29,19 +30,13 @@
|
||||
|
||||
#include "mp_image_pool.h"
|
||||
|
||||
#if HAVE_PTHREADS
|
||||
#include <pthread.h>
|
||||
static pthread_mutex_t pool_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#define pool_lock() pthread_mutex_lock(&pool_mutex)
|
||||
#define pool_unlock() pthread_mutex_unlock(&pool_mutex)
|
||||
#else
|
||||
#define pool_lock() 0
|
||||
#define pool_unlock() 0
|
||||
#endif
|
||||
|
||||
// Thread-safety: the pool itself is not thread-safe, but pool-allocated images
|
||||
// can be referenced and unreferenced from other threads. (As long as compiled
|
||||
// with pthreads, and the image destructors are thread-safe.)
|
||||
// can be referenced and unreferenced from other threads. (As long as the image
|
||||
// destructors are thread-safe.)
|
||||
|
||||
struct mp_image_pool {
|
||||
int max_count;
|
||||
|
9
wscript
9
wscript
@ -88,9 +88,11 @@ main_dependencies = [
|
||||
'desc': 'mman.h',
|
||||
'func': check_statement('sys/mman.h', 'mmap(0, 0, 0, 0, 0, 0)')
|
||||
}, {
|
||||
'name': '--pthreads',
|
||||
'name': 'pthreads',
|
||||
'desc': 'POSIX threads',
|
||||
'func': check_pthreads,
|
||||
'req': True,
|
||||
'fmsg': 'Unable to find pthreads support.'
|
||||
}, {
|
||||
'name': 'librt',
|
||||
'desc': 'linking with -lrt',
|
||||
@ -114,11 +116,6 @@ iconv support use --disable-iconv.",
|
||||
'desc': 'w32 priority API',
|
||||
'deps_any': [ 'os-win32', 'os-cygwin'],
|
||||
'func': check_true
|
||||
}, {
|
||||
'name': 'stream-cache',
|
||||
'desc': 'stream cache',
|
||||
'deps': [ 'pthreads' ],
|
||||
'func': check_true
|
||||
}, {
|
||||
'name': 'soundcard',
|
||||
'desc': 'soundcard.h',
|
||||
|
@ -226,7 +226,7 @@ def build(ctx):
|
||||
( "stream/ai_oss.c", "oss-audio" ),
|
||||
( "stream/ai_sndio.c", "sndio" ),
|
||||
( "stream/audio_in.c", "audio-input" ),
|
||||
( "stream/cache.c", "stream-cache"),
|
||||
( "stream/cache.c" ),
|
||||
( "stream/cdinfo.c", "cdda"),
|
||||
( "stream/cookies.c" ),
|
||||
( "stream/dvb_tune.c", "dvbin" ),
|
||||
|
Loading…
Reference in New Issue
Block a user