Browse Source

atomic: move atomic wait/notify to atomic header

These functions are functionally at the intersection of threading and
atomic operations. But then again, atomic operations in general are
intrinsically dependent on threading.

On the practical side, <vlc_atomic.h> is not an implicit header in
<vlc_common.h>, unlike <vlc_threads.h>. So this change actually lessens
the namespace "pollution".
pull/128/head
Rémi Denis-Courmont 5 years ago
committed by Hugo Beauzée-Luyssen
parent
commit
5d88ae1010
  1. 57
      include/vlc_atomic.h
  2. 57
      include/vlc_threads.h
  3. 2
      src/android/thread.c
  4. 1
      src/freebsd/thread.c
  5. 1
      src/linux/thread.c
  6. 1
      src/misc/threads.c
  7. 2
      src/os2/thread.c
  8. 2
      src/posix/wait.c
  9. 1
      src/win32/thread.c

57
include/vlc_atomic.h

@ -73,4 +73,61 @@ static inline uintptr_t vlc_atomic_rc_get(const vlc_atomic_rc_t* rc)
return atomic_load_explicit(&rc->refs, memory_order_relaxed);
}
/**
* Waits on an address.
*
* Puts the calling thread to sleep if a specific unsigned 32-bits value is
* stored at a specified address. The thread will sleep until it is woken up by
* a call to 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_atomic_wait(void *addr, unsigned val);
/**
* Waits on an address with a time-out.
*
* This function operates as vlc_atomic_wait() but provides an additional
* time-out. If the deadline is reached, the thread resumes and the function
* returns.
*
* \param addr address to check for
* \param val value to match at the address
* \param deadline deadline to wait until
*
* \retval 0 the function was woken up before the time-out
* \retval ETIMEDOUT the deadline was reached
*/
int vlc_atomic_timedwait(void *addr, unsigned val, vlc_tick_t deadline);
int vlc_atomic_timedwait_daytime(void *addr, unsigned val, time_t deadline);
/**
* 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_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_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_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_atomic_notify_all(void *addr);
#endif

57
include/vlc_threads.h

@ -652,63 +652,6 @@ VLC_API void *vlc_threadvar_get(vlc_threadvar_t);
/** @} */
/**
* Waits on an address.
*
* Puts the calling thread to sleep if a specific unsigned 32-bits value is
* stored at a specified address. The thread will sleep until it is woken up by
* a call to 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_atomic_wait(void *addr, unsigned val);
/**
* Waits on an address with a time-out.
*
* This function operates as vlc_atomic_wait() but provides an additional
* time-out. If the deadline is reached, the thread resumes and the function
* returns.
*
* \param addr address to check for
* \param val value to match at the address
* \param deadline deadline to wait until
*
* \retval 0 the function was woken up before the time-out
* \retval ETIMEDOUT the deadline was reached
*/
int vlc_atomic_timedwait(void *addr, unsigned val, vlc_tick_t deadline);
int vlc_atomic_timedwait_daytime(void *addr, unsigned val, time_t deadline);
/**
* 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_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_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_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_atomic_notify_all(void *addr);
/**
* Creates and starts a new thread.
*

2
src/android/thread.c

@ -43,6 +43,8 @@
#include <pthread.h>
#include <sched.h>
#include <vlc_atomic.h>
/* debug */
#ifndef NDEBUG

1
src/freebsd/thread.c

@ -32,6 +32,7 @@
#include <sys/umtx.h>
#include <vlc_common.h>
#include <vlc_atomic.h>
unsigned long vlc_thread_id(void)
{

1
src/linux/thread.c

@ -38,6 +38,7 @@
#endif
#include <vlc_common.h>
#include <vlc_atomic.h>
unsigned long vlc_thread_id(void)
{

1
src/misc/threads.c

@ -28,6 +28,7 @@
#include <stdatomic.h>
#include <vlc_common.h>
#include <vlc_atomic.h>
#include "libvlc.h"
/* <stdatomic.h> types cannot be used in the C++ view of <vlc_threads.h> */

2
src/os2/thread.c

@ -54,6 +54,8 @@
#include <sys/stat.h>
#include <vlc_atomic.h>
/* Static mutex and condition variable */
static vlc_mutex_t super_mutex;
static vlc_cond_t super_variable;

2
src/posix/wait.c

@ -32,6 +32,8 @@
#include <sys/types.h>
#include <pthread.h>
#include <vlc_atomic.h>
static clockid_t vlc_clock_id = CLOCK_REALTIME;
#define WAIT_BUCKET_INIT \

1
src/win32/thread.c

@ -43,6 +43,7 @@
#ifndef VLC_WINSTORE_APP
#include <mmsystem.h>
#endif
#include <vlc_atomic.h>
/*** Static mutex and condition variable ***/
static CRITICAL_SECTION super_mutex;

Loading…
Cancel
Save