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