VLC 4.0.0-dev
Loading...
Searching...
No Matches
vlc_atomic.h File Reference

Atomic operations do not require locking, but they are not very powerful. More...

Include dependency graph for vlc_atomic.h:

Go to the source code of this file.

Data Structures

struct  vlc_atomic_rc_t
 

Macros

#define VLC_STATIC_RC
 

Typedefs

typedef struct vlc_atomic_rc_t vlc_atomic_rc_t
 

Functions

static void vlc_atomic_rc_init (vlc_atomic_rc_t *rc)
 Init the RC to 1.
 
static void vlc_atomic_rc_inc (vlc_atomic_rc_t *rc)
 Increment the RC.
 
static bool vlc_atomic_rc_dec (vlc_atomic_rc_t *rc)
 Decrement the RC and return true if it reaches 0.
 
static uintptr_t vlc_atomic_rc_get (const vlc_atomic_rc_t *rc)
 Returns the current reference count.
 
void vlc_atomic_wait (void *addr, unsigned val)
 Waits on an address.
 
int vlc_atomic_timedwait (void *addr, unsigned val, vlc_tick_t deadline)
 Waits on an address with a time-out.
 
int vlc_atomic_timedwait_daytime (void *addr, unsigned val, 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.
 

Detailed Description

Atomic operations do not require locking, but they are not very powerful.

Macro Definition Documentation

◆ VLC_STATIC_RC

#define VLC_STATIC_RC
Value:
{ \
.refs = (uintptr_t) 1 \
}

Typedef Documentation

◆ vlc_atomic_rc_t

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, vlc_futex_wake(), vlc_umtx_wake(), wait_bucket::wait, wait_bucket_get(), wait_bucket_get(), and wait_bucket::waiters.

Referenced by vlc_atomic_notify_one(), vlc_latch_count_down_ready(), vlc_once_complete(), and vlc_queuedmutex_unlock().

◆ 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_futex_wake(), and vlc_umtx_wake().

Referenced by vlc_cancel(), vlc_cancel(), vlc_cond_signal_waiter(), vlc_mutex_unlock(), vlc_rcu_read_unlock(), and vlc_sem_post().

◆ vlc_atomic_rc_dec()

◆ vlc_atomic_rc_get()

static uintptr_t vlc_atomic_rc_get ( const vlc_atomic_rc_t rc)
inlinestatic

Returns the current reference count.

This is not safe to use for logic and must only be used for debugging or assertion purposes

References vlc_atomic_rc_t::refs.

Referenced by picture_Destroy(), picture_pool_Get(), and picture_pool_Wait().

◆ vlc_atomic_rc_inc()

◆ vlc_atomic_rc_init()

◆ 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 count, wait_bucket::lock, MS_FROM_VLC_TICK, unlikely, vlc_assert_unreachable, vlc_atomic_timedwait_timespec(), vlc_cleanup_pop, vlc_cleanup_push, vlc_futex_wait(), vlc_testcancel(), VLC_TICK_FROM_MS, vlc_tick_now(), vlc_tick_to_timespec(), vlc_timespec_adjust(), vlc_umtx_wait(), vlc_WaitForSingleObject(), wait_bucket::wait, wait_bucket_enter(), and wait_bucket_leave().

Referenced by vlc_cond_timedwait(), vlc_sem_timedwait(), and vlc_tick_wait().

◆ vlc_atomic_timedwait_daytime()

◆ 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 count, wait_bucket::lock, vlc_cleanup_pop, vlc_cleanup_push, vlc_futex_wait(), vlc_testcancel(), vlc_umtx_wait(), vlc_WaitForSingleObject(), wait_bucket::wait, wait_bucket_enter(), wait_bucket_enter(), wait_bucket_leave(), and wait_bucket_leave().

Referenced by vlc_cond_wait(), vlc_latch_wait(), vlc_mutex_lock(), vlc_once_begin(), vlc_queuedmutex_lock(), vlc_rcu_synchronize(), and vlc_sem_wait().