<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div><br></div><div><br></div><div>On Mon, Feb 17, 2020, at 15:18, Rémi Denis-Courmont wrote:<br></div><blockquote type="cite" id="qt"><div>Hi,<br></div><div><br></div><div>There is not a specific goal beyond sharing the code here. It so happens to simplify implementing timed-wait, of course. It also happens to allow eliminating destroy calls. But the patch stands alone for the generic benefits if using a common implementation of any thing.<br></div></blockquote><div><br></div><div>Thanks for the explanation.<br></div><div><br></div><div>OK for this set (after fixing problems you mentioned yourself).<br></div><div><br></div><blockquote type="cite" id="qt"><div><br></div><div class="qt-gmail_quote"><div>Le 17 février 2020 14:43:54 GMT+02:00, Thomas Guillem <thomas@gllm.fr> a écrit :<br></div><blockquote style="margin-top:0pt;margin-right:0pt;margin-bottom:0pt;margin-left:0.8ex;border-left-color:rgb(204, 204, 204);border-left-style:solid;border-left-width:1px;padding-left:1ex;" class="qt-gmail_quote"><pre class="qt-k9mail"><div>I was about to answer to your previous patch that we could use the OS semaphore for Android and Windows.<br></div><div><br></div><div>But you are now removing all OS implementation. It deserves a git message explaining why.<br></div><div><br></div><div>I'm curious to know the reason too. Is it for the timed_sem ?<br></div><div><br></div><div>On Sun, Feb 16, 2020, at 18:50, Rémi Denis-Courmont wrote:<br></div><blockquote style="margin-top:0pt;margin-right:0pt;margin-bottom:1ex;margin-left:0.8ex;border-left-color:rgb(114, 159, 207);border-left-style:solid;border-left-width:1px;padding-left:1ex;" class="qt-gmail_quote"><div><hr> include/vlc_threads.h | 14 ------------<br></div><div> src/darwin/thread.c | 45 --------------------------------------<br></div><div> src/misc/threads.c | 3 ---<br></div><div> src/posix/thread.c | 44 -------------------------------------<br></div><div> src/win32/thread.c | 51 -------------------------------------------<br></div><div> 5 files changed, 157 deletions(-)<br></div><div><br></div><div>diff --git a/include/vlc_threads.h b/include/vlc_threads.h<br></div><div>index 688855ca72..584b6416b1 100644<br></div><div>--- a/include/vlc_threads.h<br></div><div>+++ b/include/vlc_threads.h<br></div><div>@@ -70,7 +70,6 @@ typedef struct<br></div><div> } vlc_mutex_t;<br></div><div> #define VLC_STATIC_MUTEX { false, { { false, 0 } } }<br></div><div> #define LIBVLC_NEED_CONDVAR<br></div><div>-#define LIBVLC_NEED_SEMAPHORE<br></div><div> #define LIBVLC_NEED_RWLOCK<br></div><div> typedef INIT_ONCE vlc_once_t;<br></div><div> #define VLC_STATIC_ONCE INIT_ONCE_STATIC_INIT<br></div><div>@@ -123,7 +122,6 @@ typedef struct<br></div><div> unsigned signaled;<br></div><div> } vlc_cond_t;<br></div><div> #define VLC_STATIC_COND { NULLHANDLE, 0, NULLHANDLE, 0 }<br></div><div>-#define LIBVLC_NEED_SEMAPHORE<br></div><div> #define LIBVLC_NEED_RWLOCK<br></div><div> typedef struct<br></div><div> {<br></div><div>@@ -172,7 +170,6 @@ static inline int vlc_poll (struct pollfd *fds, <br></div><div>unsigned nfds, int timeout)<br></div><div> # define LIBVLC_USE_PTHREAD_CLEANUP 1<br></div><div> # define LIBVLC_NEED_SLEEP<br></div><div> # define LIBVLC_NEED_CONDVAR<br></div><div>-# define LIBVLC_NEED_SEMAPHORE<br></div><div> # define LIBVLC_NEED_RWLOCK<br></div><div> <br></div><div> typedef struct vlc_thread *vlc_thread_t;<br></div><div>@@ -226,7 +223,6 @@ typedef pthread_mutex_t vlc_mutex_t;<br></div><div> #define VLC_STATIC_MUTEX PTHREAD_MUTEX_INITIALIZER<br></div><div> typedef pthread_cond_t vlc_cond_t;<br></div><div> #define VLC_STATIC_COND PTHREAD_COND_INITIALIZER<br></div><div>-typedef semaphore_t vlc_sem_t;<br></div><div> typedef pthread_rwlock_t vlc_rwlock_t;<br></div><div> #define VLC_STATIC_RWLOCK PTHREAD_RWLOCK_INITIALIZER<br></div><div> typedef pthread_once_t vlc_once_t;<br></div><div>@@ -244,7 +240,6 @@ typedef struct vlc_timer *vlc_timer_t;<br></div><div> #else /* POSIX threads */<br></div><div> # include <unistd.h> /* _POSIX_SPIN_LOCKS */<br></div><div> # include <pthread.h><br></div><div>-# include <semaphore.h><br></div><div> <br></div><div> /**<br></div><div> * Whether LibVLC threads are based on POSIX threads.<br></div><div>@@ -299,13 +294,6 @@ typedef pthread_cond_t vlc_cond_t;<br></div><div> */<br></div><div> #define VLC_STATIC_COND PTHREAD_COND_INITIALIZER<br></div><div> <br></div><div>-/**<br></div><div>- * Semaphore.<br></div><div>- *<br></div><div>- * Storage space for a thread-safe semaphore.<br></div><div>- */<br></div><div>-typedef sem_t vlc_sem_t;<br></div><div>-<br></div><div> /**<br></div><div> * Read/write lock.<br></div><div> *<br></div><div>@@ -367,7 +355,6 @@ typedef struct<br></div><div> # define VLC_STATIC_COND { 0 }<br></div><div> #endif<br></div><div> <br></div><div>-#ifdef LIBVLC_NEED_SEMAPHORE<br></div><div> typedef struct vlc_sem<br></div><div> {<br></div><div> union {<br></div><div>@@ -377,7 +364,6 @@ typedef struct vlc_sem<br></div><div> int dummy;<br></div><div> };<br></div><div> } vlc_sem_t;<br></div><div>-#endif<br></div><div> <br></div><div> #ifdef LIBVLC_NEED_RWLOCK<br></div><div> typedef struct vlc_rwlock<br></div><div>diff --git a/src/darwin/thread.c b/src/darwin/thread.c<br></div><div>index 1eca7755d2..349a4935f3 100644<br></div><div>--- a/src/darwin/thread.c<br></div><div>+++ b/src/darwin/thread.c<br></div><div>@@ -312,51 +312,6 @@ int vlc_cond_timedwait_daytime (vlc_cond_t <br></div><div>*p_condvar, vlc_mutex_t *p_mutex,<br></div><div> }<br></div><div> <br></div><div> <br></div><div>-/* Initialize a semaphore. */<br></div><div>-void vlc_sem_init (vlc_sem_t *sem, unsigned value)<br></div><div>-{<br></div><div>- if (unlikely(semaphore_create(mach_task_self(), sem, <br></div><div>SYNC_POLICY_FIFO, value) != KERN_SUCCESS))<br></div><div>- abort ();<br></div><div>-}<br></div><div>-<br></div><div>-void vlc_sem_destroy (vlc_sem_t *sem)<br></div><div>-{<br></div><div>- int val;<br></div><div>-<br></div><div>- if (likely(semaphore_destroy(mach_task_self(), *sem) == <br></div><div>KERN_SUCCESS))<br></div><div>- return;<br></div><div>-<br></div><div>- val = EINVAL;<br></div><div>-<br></div><div>- VLC_THREAD_ASSERT ("destroying semaphore");<br></div><div>-}<br></div><div>-<br></div><div>-int vlc_sem_post (vlc_sem_t *sem)<br></div><div>-{<br></div><div>- int val;<br></div><div>-<br></div><div>- if (likely(semaphore_signal(*sem) == KERN_SUCCESS))<br></div><div>- return 0;<br></div><div>-<br></div><div>- val = EINVAL;<br></div><div>-<br></div><div>- if (unlikely(val != EOVERFLOW))<br></div><div>- VLC_THREAD_ASSERT ("unlocking semaphore");<br></div><div>- return val;<br></div><div>-}<br></div><div>-<br></div><div>-void vlc_sem_wait (vlc_sem_t *sem)<br></div><div>-{<br></div><div>- int val;<br></div><div>-<br></div><div>- if (likely(semaphore_wait(*sem) == KERN_SUCCESS))<br></div><div>- return;<br></div><div>-<br></div><div>- val = EINVAL;<br></div><div>-<br></div><div>- VLC_THREAD_ASSERT ("locking semaphore");<br></div><div>-}<br></div><div>-<br></div><div> void vlc_rwlock_init (vlc_rwlock_t *lock)<br></div><div> {<br></div><div> if (unlikely(pthread_rwlock_init (lock, NULL)))<br></div><div>diff --git a/src/misc/threads.c b/src/misc/threads.c<br></div><div>index 82bd5b60fc..ccf002be62 100644<br></div><div>--- a/src/misc/threads.c<br></div><div>+++ b/src/misc/threads.c<br></div><div>@@ -145,7 +145,6 @@ bool vlc_mutex_marked(const vlc_mutex_t *mutex)<br></div><div> #if defined (_WIN32) && (_WIN32_WINNT < _WIN32_WINNT_WIN8)<br></div><div> /* Cannot define OS version-dependent stuff in public headers */<br></div><div> # undef LIBVLC_NEED_SLEEP<br></div><div>-# undef LIBVLC_NEED_SEMAPHORE<br></div><div> #endif<br></div><div> <br></div><div> #if defined(LIBVLC_NEED_SLEEP) || defined(LIBVLC_NEED_CONDVAR)<br></div><div>@@ -396,7 +395,6 @@ void vlc_rwlock_unlock (vlc_rwlock_t *lock)<br></div><div> }<br></div><div> #endif /* LIBVLC_NEED_RWLOCK */<br></div><div> <br></div><div>-#ifdef LIBVLC_NEED_SEMAPHORE<br></div><div> /*** Generic semaphores ***/<br></div><div> <br></div><div> void vlc_sem_init (vlc_sem_t *sem, unsigned value)<br></div><div>@@ -440,4 +438,3 @@ void vlc_sem_wait (vlc_sem_t *sem)<br></div><div> }<br></div><div> }<br></div><div> }<br></div><div>-#endif /* LIBVLC_NEED_SEMAPHORE */<br></div><div>diff --git a/src/posix/thread.c b/src/posix/thread.c<br></div><div>index dfe0ea7c9d..9c9271a100 100644<br></div><div>--- a/src/posix/thread.c<br></div><div>+++ b/src/posix/thread.c<br></div><div>@@ -226,50 +226,6 @@ int vlc_cond_timedwait_daytime (vlc_cond_t <br></div><div>*p_condvar, vlc_mutex_t *p_mutex,<br></div><div> return val;<br></div><div> }<br></div><div> <br></div><div>-void vlc_sem_init (vlc_sem_t *sem, unsigned value)<br></div><div>-{<br></div><div>- if (unlikely(sem_init (sem, 0, value)))<br></div><div>- abort ();<br></div><div>-}<br></div><div>-<br></div><div>-void vlc_sem_destroy (vlc_sem_t *sem)<br></div><div>-{<br></div><div>- int val;<br></div><div>-<br></div><div>- if (likely(sem_destroy (sem) == 0))<br></div><div>- return;<br></div><div>-<br></div><div>- val = errno;<br></div><div>-<br></div><div>- VLC_THREAD_ASSERT ("destroying semaphore");<br></div><div>-}<br></div><div>-<br></div><div>-int vlc_sem_post (vlc_sem_t *sem)<br></div><div>-{<br></div><div>- int val;<br></div><div>-<br></div><div>- if (likely(sem_post (sem) == 0))<br></div><div>- return 0;<br></div><div>-<br></div><div>- val = errno;<br></div><div>-<br></div><div>- if (unlikely(val != EOVERFLOW))<br></div><div>- VLC_THREAD_ASSERT ("unlocking semaphore");<br></div><div>- return val;<br></div><div>-}<br></div><div>-<br></div><div>-void vlc_sem_wait (vlc_sem_t *sem)<br></div><div>-{<br></div><div>- int val;<br></div><div>-<br></div><div>- do<br></div><div>- if (likely(sem_wait (sem) == 0))<br></div><div>- return;<br></div><div>- while ((val = errno) == EINTR);<br></div><div>-<br></div><div>- VLC_THREAD_ASSERT ("locking semaphore");<br></div><div>-}<br></div><div>-<br></div><div> void vlc_rwlock_init (vlc_rwlock_t *lock)<br></div><div> {<br></div><div> if (unlikely(pthread_rwlock_init (lock, NULL)))<br></div><div>diff --git a/src/win32/thread.c b/src/win32/thread.c<br></div><div>index 7bc6196519..4d6d7bdb5d 100644<br></div><div>--- a/src/win32/thread.c<br></div><div>+++ b/src/win32/thread.c<br></div><div>@@ -154,57 +154,6 @@ void vlc_mutex_unlock (vlc_mutex_t *p_mutex)<br></div><div> vlc_mutex_unmark(p_mutex);<br></div><div> }<br></div><div> <br></div><div>-/*** Semaphore ***/<br></div><div>-#if (_WIN32_WINNT < _WIN32_WINNT_WIN8)<br></div><div>-# include <stdalign.h><br></div><div>-<br></div><div>-static inline HANDLE *vlc_sem_handle_p(vlc_sem_t *sem)<br></div><div>-{<br></div><div>- /* NOTE: vlc_sem_t layout cannot easily depend on Windows version */<br></div><div>- static_assert (sizeof (HANDLE) <= sizeof (vlc_sem_t), "Size mismatch!");<br></div><div>- static_assert ((alignof (HANDLE) % alignof (vlc_sem_t)) == 0,<br></div><div>- "Alignment mismatch");<br></div><div>- return (HANDLE *)sem;<br></div><div>-}<br></div><div>-#define vlc_sem_handle(sem) (*vlc_sem_handle_p(sem))<br></div><div>-<br></div><div>-void vlc_sem_init (vlc_sem_t *sem, unsigned value)<br></div><div>-{<br></div><div>- HANDLE handle = CreateSemaphore(NULL, value, 0x7fffffff, NULL);<br></div><div>- if (handle == NULL)<br></div><div>- abort ();<br></div><div>-<br></div><div>- vlc_sem_handle(sem) = handle;<br></div><div>-}<br></div><div>-<br></div><div>-void vlc_sem_destroy (vlc_sem_t *sem)<br></div><div>-{<br></div><div>- CloseHandle(vlc_sem_handle(sem));<br></div><div>-}<br></div><div>-<br></div><div>-int vlc_sem_post (vlc_sem_t *sem)<br></div><div>-{<br></div><div>- ReleaseSemaphore(vlc_sem_handle(sem), 1, NULL);<br></div><div>- return 0; /* FIXME */<br></div><div>-}<br></div><div>-<br></div><div>-void vlc_sem_wait (vlc_sem_t *sem)<br></div><div>-{<br></div><div>- HANDLE handle = vlc_sem_handle(sem);<br></div><div>- DWORD result;<br></div><div>-<br></div><div>- do<br></div><div>- {<br></div><div>- vlc_testcancel ();<br></div><div>- result = WaitForSingleObjectEx(handle, INFINITE, TRUE);<br></div><div>-<br></div><div>- /* Semaphore abandoned would be a bug. */<br></div><div>- assert(result != WAIT_ABANDONED_0);<br></div><div>- }<br></div><div>- while (result == WAIT_IO_COMPLETION || result == WAIT_FAILED);<br></div><div>-}<br></div><div>-#endif<br></div><div>-<br></div><div> /*** One-time initialization ***/<br></div><div> static BOOL CALLBACK vlc_once_callback(INIT_ONCE *once, void *parm, void **ctx)<br></div><div> {<br></div><div>-- <br></div><div>2.25.0<hr>vlc-devel mailing list<br></div><div>To unsubscribe or modify your subscription options:<br></div><div><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></div></blockquote><div><hr>vlc-devel mailing list<br></div><div>To unsubscribe or modify your subscription options:<br></div><div><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br></div></pre></blockquote></div><div><br></div><div>-- <br></div><div>Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté. <br></div><div>_______________________________________________<br></div><div>vlc-devel mailing list<br></div><div>To unsubscribe or modify your subscription options:<br></div><div>https://mailman.videolan.org/listinfo/vlc-devel<br></div></blockquote><div><br></div></body></html>