[vlc-devel] [PATCH] threads: rename vlc_addr_* following C++20 names
Rémi Denis-Courmont
remi at remlab.net
Tue Feb 4 09:10:47 CET 2020
Hi,
They are not implemented on non-Linux non-Windows as of yet. Exposing them would break libvlccore linking on macos.
Le 4 février 2020 09:41:03 GMT+02:00, Steve Lhomme <robux4 at ycbcr.xyz> a écrit :
>Looks OK to me.
>I'm suprised these are only used by the core and don't have VLC_API.
>Shouldn't parts of the header be moved in the core then ? Or should
>these APIs be made available to anyone ?
>
>On 2020-02-03 20:35, Rémi Denis-Courmont wrote:
>> Use C++20 draft-like names instead of custom
>neither-Linux-nor-Windows
>> ones.
>>
>> Note though that C++ has no timed variant for its atomic wait method.
>> ---
>> include/vlc_threads.h | 20 +++++++++++---------
>> src/android/thread.c | 2 +-
>> src/linux/thread.c | 8 ++++----
>> src/misc/threads.c | 10 +++++-----
>> src/win32/thread.c | 10 +++++-----
>> 5 files changed, 26 insertions(+), 24 deletions(-)
>>
>> diff --git a/include/vlc_threads.h b/include/vlc_threads.h
>> index 315729a097..8a39c61087 100644
>> --- a/include/vlc_threads.h
>> +++ b/include/vlc_threads.h
>> @@ -688,19 +688,20 @@ VLC_API void
>*vlc_threadvar_get(vlc_threadvar_t);
>> *
>> * Puts the calling thread to sleep if a specific value is stored
>at a
>> * specified address. The thread will sleep until it is woken up by
>a call to
>> - * vlc_addr_signal() or vlc_addr_broadcast() in another thread, or
>spuriously.
>> + * vlc_atomic_notify_one() or vlc_atomic_notify_all() in another
>thread, or
>> + * spuriously.
>> *
>> * If the value does not match, do nothing and return immediately.
>> *
>> * \param addr address to check for
>> * \param val value to match at the address
>> */
>> -void vlc_addr_wait(void *addr, unsigned val);
>> +void vlc_atomic_wait(void *addr, unsigned val);
>>
>> /**
>> * Waits on an address with a time-out.
>> *
>> - * This function operates as vlc_addr_wait() but provides an
>additional
>> + * This function operates as vlc_atomic_wait() but provides an
>additional
>> * time-out. If the time-out elapses, the thread resumes and the
>function
>> * returns.
>> *
>> @@ -711,30 +712,31 @@ void vlc_addr_wait(void *addr, unsigned val);
>> * \return true if the function was woken up before the time-out,
>> * false if the time-out elapsed.
>> */
>> -bool vlc_addr_timedwait(void *addr, unsigned val, vlc_tick_t delay);
>> +bool vlc_atomic_timedwait(void *addr, unsigned val, vlc_tick_t
>delay);
>>
>> /**
>> * Wakes up one thread on an address.
>> *
>> * Wakes up (at least) one of the thread sleeping on the specified
>address.
>> * The address must be equal to the first parameter given by at
>least one
>> - * thread sleeping within the vlc_addr_wait() or
>vlc_addr_timedwait()
>> + * thread sleeping within the vlc_atomic_wait() or
>vlc_atomic_timedwait()
>> * functions. If no threads are found, this function does nothing.
>> *
>> * \param addr address identifying which threads may be woken up
>> */
>> -void vlc_addr_signal(void *addr);
>> +void vlc_atomic_notify_one(void *addr);
>>
>> /**
>> * Wakes up all thread on an address.
>> *
>> * Wakes up all threads sleeping on the specified address (if any).
>> - * Any thread sleeping within a call to vlc_addr_wait() or
>vlc_addr_timedwait()
>> - * with the specified address as first call parameter will be woken
>up.
>> + * Any thread sleeping within a call to vlc_atomic_wait() or
>> + * vlc_atomic_timedwait() with the specified address as first call
>parameter
>> + * will be woken up.
>> *
>> * \param addr address identifying which threads to wake up
>> */
>> -void vlc_addr_broadcast(void *addr);
>> +void vlc_atomic_notify_all(void *addr);
>>
>> /**
>> * Creates and starts a new thread.
>> diff --git a/src/android/thread.c b/src/android/thread.c
>> index 0d9191592e..ca715418d4 100644
>> --- a/src/android/thread.c
>> +++ b/src/android/thread.c
>> @@ -293,7 +293,7 @@ void vlc_cancel (vlc_thread_t thread_id)
>> if (addr != NULL)
>> {
>> atomic_fetch_or_explicit(addr, 1, memory_order_relaxed);
>> - vlc_addr_broadcast(addr);
>> + vlc_atomic_notify_all(addr);
>> }
>> vlc_mutex_unlock(&thread_id->wait.lock);
>> }
>> diff --git a/src/linux/thread.c b/src/linux/thread.c
>> index 7e9dab63bd..5a89cfa44a 100644
>> --- a/src/linux/thread.c
>> +++ b/src/linux/thread.c
>> @@ -68,22 +68,22 @@ static int vlc_futex_wait(void *addr, unsigned
>val, const struct timespec *to)
>> return ret;
>> }
>>
>> -void vlc_addr_signal(void *addr)
>> +void vlc_atomic_notify_one(void *addr)
>> {
>> vlc_futex_wake(addr, 1);
>> }
>>
>> -void vlc_addr_broadcast(void *addr)
>> +void vlc_atomic_notify_all(void *addr)
>> {
>> vlc_futex_wake(addr, INT_MAX);
>> }
>>
>> -void vlc_addr_wait(void *addr, unsigned val)
>> +void vlc_atomic_wait(void *addr, unsigned val)
>> {
>> vlc_futex_wait(addr, val, NULL);
>> }
>>
>> -bool vlc_addr_timedwait(void *addr, unsigned val, vlc_tick_t delay)
>> +bool vlc_atomic_timedwait(void *addr, unsigned val, vlc_tick_t
>delay)
>> {
>> struct timespec ts = timespec_from_vlc_tick(delay);
>>
>> diff --git a/src/misc/threads.c b/src/misc/threads.c
>> index d267cc7344..501a17ac9b 100644
>> --- a/src/misc/threads.c
>> +++ b/src/misc/threads.c
>> @@ -177,7 +177,7 @@ void (vlc_tick_wait)(vlc_tick_t deadline)
>>
>> while ((delay = (deadline - vlc_tick_now())) > 0)
>> {
>> - vlc_addr_timedwait(&value, 0, delay);
>> + vlc_atomic_timedwait(&value, 0, delay);
>> vlc_testcancel();
>> }
>>
>> @@ -236,13 +236,13 @@ void vlc_cond_signal(vlc_cond_t *cond)
>> * - cnd_wait() sets the futex to the equal-or-next even value.
>> **/
>> atomic_fetch_or_explicit(vlc_cond_value(cond), 1,
>memory_order_relaxed);
>> - vlc_addr_signal(&cond->value);
>> + vlc_atomic_notify_one(&cond->value);
>> }
>>
>> void vlc_cond_broadcast(vlc_cond_t *cond)
>> {
>> atomic_fetch_or_explicit(vlc_cond_value(cond), 1,
>memory_order_relaxed);
>> - vlc_addr_broadcast(&cond->value);
>> + vlc_atomic_notify_all(&cond->value);
>> }
>>
>> void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t *mutex)
>> @@ -261,7 +261,7 @@ void vlc_cond_wait(vlc_cond_t *cond, vlc_mutex_t
>*mutex)
>> vlc_cancel_addr_prepare(&cond->value);
>> vlc_mutex_unlock(mutex);
>>
>> - vlc_addr_wait(&cond->value, value);
>> + vlc_atomic_wait(&cond->value, value);
>>
>> vlc_mutex_lock(mutex);
>> vlc_cancel_addr_finish(&cond->value);
>> @@ -285,7 +285,7 @@ static int vlc_cond_wait_delay(vlc_cond_t *cond,
>vlc_mutex_t *mutex,
>> vlc_mutex_unlock(mutex);
>>
>> if (delay > 0)
>> - value = vlc_addr_timedwait(&cond->value, value, delay);
>> + value = vlc_atomic_timedwait(&cond->value, value, delay);
>> else
>> value = 0;
>>
>> diff --git a/src/win32/thread.c b/src/win32/thread.c
>> index d4fc433cae..07423af530 100644
>> --- a/src/win32/thread.c
>> +++ b/src/win32/thread.c
>> @@ -424,12 +424,12 @@ static void WINAPI WakeByAddressFallback(void
>*addr)
>> }
>> #endif
>>
>> -void vlc_addr_wait(void *addr, unsigned val)
>> +void vlc_atomic_wait(void *addr, unsigned val)
>> {
>> WaitOnAddress(addr, &val, sizeof (val), -1);
>> }
>>
>> -bool vlc_addr_timedwait(void *addr, unsigned val, vlc_tick_t delay)
>> +bool vlc_atomic_timedwait(void *addr, unsigned val, vlc_tick_t
>delay)
>> {
>> delay = (delay + (1000-1)) / 1000;
>>
>> @@ -442,12 +442,12 @@ bool vlc_addr_timedwait(void *addr, unsigned
>val, vlc_tick_t delay)
>> return WaitOnAddress(addr, &val, sizeof (val), delay);
>> }
>>
>> -void vlc_addr_signal(void *addr)
>> +void vlc_atomic_notify_one(void *addr)
>> {
>> WakeByAddressSingle(addr);
>> }
>>
>> -void vlc_addr_broadcast(void *addr)
>> +void vlc_atomic_notify_all(void *addr)
>> {
>> WakeByAddressAll(addr);
>> }
>> @@ -585,7 +585,7 @@ void vlc_cancel (vlc_thread_t th)
>> if (th->wait.addr != NULL)
>> {
>> atomic_fetch_or_explicit(th->wait.addr, 1,
>memory_order_relaxed);
>> - vlc_addr_broadcast(th->wait.addr);
>> + vlc_atomic_notify_all(th->wait.addr);
>> }
>> LeaveCriticalSection(&th->wait.lock);
>>
>> --
>> 2.25.0
>>
>> _______________________________________________
>> vlc-devel mailing list
>> To unsubscribe or modify your subscription options:
>> https://mailman.videolan.org/listinfo/vlc-devel
>>
>_______________________________________________
>vlc-devel mailing list
>To unsubscribe or modify your subscription options:
>https://mailman.videolan.org/listinfo/vlc-devel
--
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20200204/221958f1/attachment.html>
More information about the vlc-devel
mailing list