VLC  4.0.0-dev
Data Structures | Macros | Functions | Variables
thread.c File Reference
Include dependency graph for thread.c:

Data Structures

struct  vlc_thread
 
struct  vlc_threadvar
 

Macros

#define _DECL_DLLMAIN
 
#define IS_INTERRUPTIBLE   (1)
 
#define ABOVE_NORMAL_PRIORITY_CLASS   0x00008000
 
#define LOOKUP(s)   (((s##_) = (void *)GetProcAddress(h, #s)) != NULL)
 

Functions

int vlc_threadvar_create (vlc_threadvar_t *p_tls, void(*destr)(void *))
 Allocates a thread-specific variable. More...
 
void vlc_threadvar_delete (vlc_threadvar_t *p_tls)
 Deallocates a thread-specific variable. More...
 
int vlc_threadvar_set (vlc_threadvar_t key, void *value)
 Sets a thread-specific variable. More...
 
void * vlc_threadvar_get (vlc_threadvar_t key)
 Gets the value of a thread-local variable for the calling thread. More...
 
static void vlc_threadvars_cleanup (void)
 
void vlc_atomic_wait (void *addr, unsigned val)
 Waits on an address. More...
 
int vlc_atomic_timedwait (void *addr, unsigned val, vlc_tick_t deadline)
 Waits on an address with a time-out. More...
 
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. More...
 
void vlc_atomic_notify_all (void *addr)
 Wakes up all thread on an address. More...
 
static unsigned __stdcall vlc_entry (void *p)
 
int vlc_clone (vlc_thread_t *p_handle, void *(*entry)(void *), void *data, int priority)
 Creates and starts a new thread. More...
 
void vlc_join (vlc_thread_t th, void **result)
 Waits for a thread to complete (if needed), then destroys it. More...
 
unsigned long vlc_thread_id (void)
 Thread identifier. More...
 
int vlc_set_priority (vlc_thread_t th, int priority)
 
static void CALLBACK vlc_cancel_self (ULONG_PTR self)
 
void vlc_cancel (vlc_thread_t th)
 Marks a thread as cancelled. More...
 
int vlc_savecancel (void)
 Disables thread cancellation. More...
 
void vlc_restorecancel (int state)
 Restores the cancellation state. More...
 
static noreturn void vlc_docancel (struct vlc_thread *th)
 
void vlc_testcancel (void)
 Issues an explicit deferred cancellation point. More...
 
void vlc_control_cancel (vlc_cleanup_t *cleaner)
 Internal handler for thread cancellation. More...
 
static vlc_tick_t mdate_interrupt (void)
 
static vlc_tick_t mdate_tick (void)
 
static vlc_tick_t mdate_perf (void)
 
static vlc_tick_t mdate_perf_100ns (void)
 
static vlc_tick_t mdate_wall (void)
 
static vlc_tick_t mdate_default (void)
 
vlc_tick_t vlc_tick_now (void)
 Precision monotonic clock. More...
 
void() vlc_tick_wait (vlc_tick_t deadline)
 
void() vlc_tick_sleep (vlc_tick_t delay)
 
static BOOL SelectClockSource (vlc_object_t *obj)
 
unsigned vlc_GetCPUCount (void)
 Count CPUs. More...
 
void vlc_threads_setup (libvlc_int_t *vlc)
 
BOOL WINAPI DllMain (HANDLE hinstDll, DWORD fdwReason, LPVOID lpvReserved)
 

Variables

static SRWLOCK super_lock = SRWLOCK_INIT
 
static thread_local struct vlc_threadcurrent_thread_ctx = NULL
 
struct vlc_threadvarvlc_threadvar_last = NULL
 
union {
   struct {
      LARGE_INTEGER   freq
 
   }   perf
 
clk
 
static vlc_tick_t(* mdate_selected )(void) = mdate_default
 
static SRWLOCK setup_lock = SRWLOCK_INIT
 

Macro Definition Documentation

◆ _DECL_DLLMAIN

#define _DECL_DLLMAIN

◆ ABOVE_NORMAL_PRIORITY_CLASS

#define ABOVE_NORMAL_PRIORITY_CLASS   0x00008000

◆ IS_INTERRUPTIBLE

#define IS_INTERRUPTIBLE   (1)

◆ LOOKUP

#define LOOKUP (   s)    (((s##_) = (void *)GetProcAddress(h, #s)) != NULL)

Function Documentation

◆ DllMain()

BOOL WINAPI DllMain ( HANDLE  hinstDll,
DWORD  fdwReason,
LPVOID  lpvReserved 
)

References LOOKUP, and vlc_threadvars_cleanup().

◆ mdate_default()

static vlc_tick_t mdate_default ( void  )
static

References mdate_perf(), and vlc_threads_setup().

Referenced by vlc_threads_setup().

◆ mdate_interrupt()

static vlc_tick_t mdate_interrupt ( void  )
static

References CLOCK_FREQ, static_assert, and unlikely.

Referenced by SelectClockSource().

◆ mdate_perf()

static vlc_tick_t mdate_perf ( void  )
static

References clk, unlikely, and vlc_tick_from_frac().

Referenced by mdate_default(), and SelectClockSource().

◆ mdate_perf_100ns()

static vlc_tick_t mdate_perf_100ns ( void  )
static

References unlikely, and VLC_TICK_FROM_MSFTIME.

Referenced by SelectClockSource().

◆ mdate_tick()

static vlc_tick_t mdate_tick ( void  )
static

◆ mdate_wall()

static vlc_tick_t mdate_wall ( void  )
static

◆ SelectClockSource()

static BOOL SelectClockSource ( vlc_object_t obj)
static

◆ 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

◆ 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

◆ 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 MS_FROM_VLC_TICK, VLC_TICK_FROM_MS, and vlc_tick_now().

◆ vlc_atomic_timedwait_daytime()

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

◆ 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

◆ vlc_cancel_self()

static void CALLBACK vlc_cancel_self ( ULONG_PTR  self)
static

Referenced by vlc_cancel().

◆ vlc_docancel()

static noreturn void vlc_docancel ( struct vlc_thread th)
static

◆ vlc_entry()

static unsigned __stdcall vlc_entry ( void *  p)
static

◆ vlc_set_priority()

int vlc_set_priority ( vlc_thread_t  th,
int  priority 
)

References VLC_EGENERIC, and VLC_SUCCESS.

◆ vlc_threads_setup()

void vlc_threads_setup ( libvlc_int_t vlc)

◆ vlc_threadvars_cleanup()

static void vlc_threadvars_cleanup ( void  )
static

◆ vlc_tick_sleep()

void() vlc_tick_sleep ( vlc_tick_t  delay)

References vlc_tick_now(), and vlc_tick_wait().

◆ vlc_tick_wait()

void() vlc_tick_wait ( vlc_tick_t  deadline)

Variable Documentation

◆ 

union { ... } clk

Referenced by mdate_perf(), and SelectClockSource().

◆ current_thread_ctx

thread_local struct vlc_thread* current_thread_ctx = NULL
static

◆ freq

LARGE_INTEGER freq

Referenced by rtp_queue(), and vlc_tick_now().

◆ mdate_selected

vlc_tick_t(* mdate_selected) (void) ( void  ) = mdate_default
static

◆ 

struct { ... } perf

◆ setup_lock

SRWLOCK setup_lock = SRWLOCK_INIT
static

Referenced by vlc_threads_setup().

◆ super_lock

SRWLOCK super_lock = SRWLOCK_INIT
static

◆ vlc_threadvar_last

struct vlc_threadvar * vlc_threadvar_last = NULL