VLC 4.0.0-dev
Loading...
Searching...
No Matches
wait.c File Reference
Include dependency graph for wait.c:

Data Structures

struct  wait_bucket
 

Macros

#define WAIT_BUCKET_INIT    { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 }
 
#define WAIT_BUCKET_INIT_2   WAIT_BUCKET_INIT, WAIT_BUCKET_INIT
 
#define WAIT_BUCKET_INIT_4   WAIT_BUCKET_INIT_2, WAIT_BUCKET_INIT_2
 
#define WAIT_BUCKET_INIT_8   WAIT_BUCKET_INIT_4, WAIT_BUCKET_INIT_4
 
#define WAIT_BUCKET_INIT_16   WAIT_BUCKET_INIT_8, WAIT_BUCKET_INIT_8
 
#define WAIT_BUCKET_INIT_32   WAIT_BUCKET_INIT_16, WAIT_BUCKET_INIT_16
 

Functions

static struct wait_bucketwait_bucket_get (atomic_uint *addr)
 
static struct wait_bucketwait_bucket_enter (atomic_uint *addr)
 
static void wait_bucket_leave (struct wait_bucket *bucket)
 
void vlc_atomic_wait (void *addr, unsigned value)
 Waits on an address.
 
static int vlc_atomic_timedwait_timespec (void *addr, unsigned value, const struct timespec *restrict ts)
 
static void vlc_timespec_adjust (clockid_t cid, struct timespec *restrict ts)
 
int vlc_atomic_timedwait (void *addr, unsigned value, vlc_tick_t deadline)
 Waits on an address with a time-out.
 
int vlc_atomic_timedwait_daytime (void *addr, unsigned value, time_t deadline)
 
void vlc_atomic_notify_one (void *addr)
 Wakes up one thread on an address.
 
void vlc_atomic_notify_all (void *addr)
 Wakes up all thread on an address.
 

Variables

static clockid_t vlc_clock_id = CLOCK_REALTIME
 
static struct wait_bucket wait_buckets [32] = { { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } }
 

Macro Definition Documentation

◆ WAIT_BUCKET_INIT

#define WAIT_BUCKET_INIT    { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 }

◆ WAIT_BUCKET_INIT_16

#define WAIT_BUCKET_INIT_16   WAIT_BUCKET_INIT_8, WAIT_BUCKET_INIT_8

◆ WAIT_BUCKET_INIT_2

#define WAIT_BUCKET_INIT_2   WAIT_BUCKET_INIT, WAIT_BUCKET_INIT

◆ WAIT_BUCKET_INIT_32

#define WAIT_BUCKET_INIT_32   WAIT_BUCKET_INIT_16, WAIT_BUCKET_INIT_16

◆ WAIT_BUCKET_INIT_4

#define WAIT_BUCKET_INIT_4   WAIT_BUCKET_INIT_2, WAIT_BUCKET_INIT_2

◆ WAIT_BUCKET_INIT_8

#define WAIT_BUCKET_INIT_8   WAIT_BUCKET_INIT_4, WAIT_BUCKET_INIT_4

Function Documentation

◆ vlc_atomic_notify_all()

void vlc_atomic_notify_all ( 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.

Parameters
addraddress identifying which threads to wake up

References wait_bucket::lock, wait_bucket::wait, wait_bucket_get(), and wait_bucket::waiters.

Referenced by vlc_atomic_notify_one().

◆ vlc_atomic_notify_one()

void vlc_atomic_notify_one ( void *  addr)

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.

Parameters
addraddress identifying which threads may be woken up

References vlc_atomic_notify_all().

◆ vlc_atomic_timedwait()

int vlc_atomic_timedwait ( void *  addr,
unsigned  val,
vlc_tick_t  deadline 
)

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.

Parameters
addraddress to check for
valvalue to match at the address
deadlinedeadline to wait until
Return values
0the function was woken up before the time-out
ETIMEDOUTthe deadline was reached

References vlc_atomic_timedwait_timespec(), vlc_tick_to_timespec(), and vlc_timespec_adjust().

◆ vlc_atomic_timedwait_daytime()

int vlc_atomic_timedwait_daytime ( void *  addr,
unsigned  value,
time_t  deadline 
)

◆ vlc_atomic_timedwait_timespec()

static int vlc_atomic_timedwait_timespec ( void *  addr,
unsigned  value,
const struct timespec *restrict  ts 
)
static

◆ vlc_atomic_wait()

void vlc_atomic_wait ( void *  addr,
unsigned  val 
)

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.

Parameters
addraddress to check for
valvalue to match at the address

References wait_bucket::lock, wait_bucket::wait, wait_bucket_enter(), and wait_bucket_leave().

◆ vlc_timespec_adjust()

static void vlc_timespec_adjust ( clockid_t  cid,
struct timespec *restrict  ts 
)
static

◆ wait_bucket_enter()

static struct wait_bucket * wait_bucket_enter ( atomic_uint *  addr)
static

◆ wait_bucket_get()

static struct wait_bucket * wait_bucket_get ( atomic_uint *  addr)
static

◆ wait_bucket_leave()

static void wait_bucket_leave ( struct wait_bucket bucket)
static

Variable Documentation

◆ vlc_clock_id

clockid_t vlc_clock_id = CLOCK_REALTIME
static

Referenced by vlc_timespec_adjust().

◆ wait_buckets

struct wait_bucket wait_buckets[32] = { { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } , { PTHREAD_MUTEX_INITIALIZER, PTHREAD_COND_INITIALIZER, 0 } }
static

Referenced by wait_bucket_get().