diff --git a/include/vlc_threads.h b/include/vlc_threads.h index f70094df24..df83468f53 100644 --- a/include/vlc_threads.h +++ b/include/vlc_threads.h @@ -398,8 +398,6 @@ VLC_API void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex); VLC_API int vlc_cond_timedwait(vlc_cond_t *cond, vlc_mutex_t *mutex, vlc_tick_t deadline); -int vlc_cond_timedwait_daytime(vlc_cond_t *, vlc_mutex_t *, time_t); - /** @} */ /** @@ -567,50 +565,6 @@ VLC_API void vlc_latch_wait(vlc_latch_t *); /** @} */ -/* - * Queued mutex - * - * A queued mutex is a type of thread-safe mutual exclusion lock that is - * acquired in strict FIFO order. - * - * In most cases, a regular mutex (\ref vlc_mutex_t) should be used instead. - * There are important differences: - * - A queued mutex is generally slower, especially on the fast path. - * - A queued mutex cannot be combined with a condition variable. - * Indeed, the scheduling policy of the condition variable would typically - * conflict with that of the queued mutex, leading to a dead lock. - * - The try-lock operation is not implemented. - */ -typedef struct { - atomic_uint head; - atomic_uint tail; - atomic_ulong owner; -} vlc_queuedmutex_t; - -#define VLC_STATIC_QUEUEDMUTEX { ATOMIC_VAR_INIT(0), ATOMIC_VAR_INIT(0), ATOMIC_VAR_INIT(0) } - -void vlc_queuedmutex_init(vlc_queuedmutex_t *m); - -void vlc_queuedmutex_lock(vlc_queuedmutex_t *m); - -void vlc_queuedmutex_unlock(vlc_queuedmutex_t *m); - -/** - * Checks if a queued mutex is locked. - * - * This function checks if the calling thread holds a given queued mutual - * exclusion lock. It has no side effects and is essentially intended for - * run-time debugging. - * - * @note To assert that the calling thread holds a lock, the helper macro - * vlc_queuedmutex_assert() should be used instead of this function. - * - * @retval false the mutex is not locked by the calling thread - * @retval true the mutex is locked by the calling thread - */ -bool vlc_queuedmutex_held(vlc_queuedmutex_t *m); - -#define vlc_queuedmutex_assert(m) assert(vlc_queuedmutex_held(m)) /** * One-time initialization. * diff --git a/src/Makefile.am b/src/Makefile.am index 9b8c896b8f..73ccdd5da3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -391,6 +391,7 @@ libvlccore_la_SOURCES = \ misc/rcu.c \ misc/renderer_discovery.c \ misc/threads.c \ + misc/threads.h \ misc/cpu.c \ misc/diffutil.c \ misc/epg.c \ diff --git a/src/input/vlm.c b/src/input/vlm.c index 0fb728ceff..bd29b2aab6 100644 --- a/src/input/vlm.c +++ b/src/input/vlm.c @@ -47,6 +47,7 @@ #include "vlm_event.h" #include #include +#include "../misc/threads.h" #include "../libvlc.h" /***************************************************************************** @@ -976,4 +977,3 @@ int vlm_Control( vlm_t *p_vlm, int i_query, ... ) return i_result; } - diff --git a/src/misc/threads.c b/src/misc/threads.c index e16849abbd..8f30991910 100644 --- a/src/misc/threads.c +++ b/src/misc/threads.c @@ -31,6 +31,7 @@ #include #include #include "libvlc.h" +#include "threads.h" /* types cannot be used in the C++ view of */ struct vlc_suuint { union { unsigned int value; }; }; diff --git a/src/misc/threads.h b/src/misc/threads.h new file mode 100644 index 0000000000..2237c57f0c --- /dev/null +++ b/src/misc/threads.h @@ -0,0 +1,79 @@ +/***************************************************************************** + * threads.h : core internal threads implementation for the VideoLAN client + ***************************************************************************** + * Copyright (C) 1999, 2002 VLC authors and VideoLAN + * Copyright © 2007-2016 Rémi Denis-Courmont + * + * Authors: Jean-Marc Dressler + * Samuel Hocevar + * Gildas Bazin + * Christophe Massiot + * + * This program 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. + * + * This program 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 this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#ifndef VLC_CORE_THREADS_H_ +#define VLC_CORE_THREADS_H_ + +#include + +int vlc_cond_timedwait_daytime(vlc_cond_t *, vlc_mutex_t *, time_t); + +/* + * Queued mutex + * + * A queued mutex is a type of thread-safe mutual exclusion lock that is + * acquired in strict FIFO order. + * + * In most cases, a regular mutex (\ref vlc_mutex_t) should be used instead. + * There are important differences: + * - A queued mutex is generally slower, especially on the fast path. + * - A queued mutex cannot be combined with a condition variable. + * Indeed, the scheduling policy of the condition variable would typically + * conflict with that of the queued mutex, leading to a dead lock. + * - The try-lock operation is not implemented. + */ +typedef struct { + atomic_uint head; + atomic_uint tail; + atomic_ulong owner; +} vlc_queuedmutex_t; + +#define VLC_STATIC_QUEUEDMUTEX { ATOMIC_VAR_INIT(0), ATOMIC_VAR_INIT(0), ATOMIC_VAR_INIT(0) } + +void vlc_queuedmutex_init(vlc_queuedmutex_t *m); + +void vlc_queuedmutex_lock(vlc_queuedmutex_t *m); + +void vlc_queuedmutex_unlock(vlc_queuedmutex_t *m); + +/** + * Checks if a queued mutex is locked. + * + * This function checks if the calling thread holds a given queued mutual + * exclusion lock. It has no side effects and is essentially intended for + * run-time debugging. + * + * @note To assert that the calling thread holds a lock, the helper macro + * vlc_queuedmutex_assert() should be used instead of this function. + * + * @retval false the mutex is not locked by the calling thread + * @retval true the mutex is locked by the calling thread + */ +bool vlc_queuedmutex_held(vlc_queuedmutex_t *m); + +#define vlc_queuedmutex_assert(m) assert(vlc_queuedmutex_held(m)) + +#endif /* !VLC_CORE_THREADS_H_ */ diff --git a/src/video_output/video_output.c b/src/video_output/video_output.c index c35f1ff4f2..9feef8ae64 100644 --- a/src/video_output/video_output.c +++ b/src/video_output/video_output.c @@ -60,6 +60,7 @@ #include "snapshot.h" #include "video_window.h" #include "../misc/variables.h" +#include "../misc/threads.h" #include "../clock/clock.h" #include "statistic.h" #include "chrono.h"