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

Data Structures

struct  task
 
struct  background_thread
 
struct  background_worker
 

Functions

static struct tasktask_Create (struct background_worker *worker, void *id, void *entity, int timeout)
 
static void task_Destroy (struct background_worker *worker, struct task *task)
 
static struct taskQueueTake (struct background_worker *worker, int timeout_ms)
 
static void QueuePush (struct background_worker *worker, struct task *task)
 
static void QueueRemoveAll (struct background_worker *worker, void *id)
 
static struct background_threadbackground_thread_Create (struct background_worker *owner)
 
static void background_thread_Destroy (struct background_thread *thread)
 
static struct background_workerbackground_worker_Create (void *owner, struct background_worker_config *conf)
 
static void background_worker_Destroy (struct background_worker *worker)
 
static void TerminateTask (struct background_thread *thread, struct task *task)
 
static void RemoveThread (struct background_thread *thread)
 
static void * Thread (void *data)
 
static bool SpawnThread (struct background_worker *worker)
 
struct background_workerbackground_worker_New (void *owner, struct background_worker_config *conf)
 Create a background-worker. More...
 
int background_worker_Push (struct background_worker *worker, void *entity, void *id, int timeout)
 Push an entity into the background-worker. More...
 
static void BackgroundWorkerCancelLocked (struct background_worker *worker, void *id)
 
void background_worker_Cancel (struct background_worker *worker, void *id)
 Remove entities from the background-worker. More...
 
void background_worker_RequestProbe (struct background_worker *worker)
 Request the background-worker to probe the current task. More...
 
void background_worker_Delete (struct background_worker *worker)
 Delete a background-worker. More...
 

Function Documentation

◆ background_thread_Create()

static struct background_thread* background_thread_Create ( struct background_worker owner)
static

◆ background_thread_Destroy()

static void background_thread_Destroy ( struct background_thread thread)
static

Referenced by RemoveThread().

◆ background_worker_Cancel()

void background_worker_Cancel ( struct background_worker worker,
void *  id 
)

Remove entities from the background-worker.

This function is used to remove processing of a certain entity given its associated id, or to remove all queued (including currently running) entities.

Warning
if the id passed refers to an entity that is currently being processed, the call will block until the task has been terminated.
Parameters
workerthe background-worker
idNULL if every entity shall be removed, and the currently running task (if any) shall be cancelled.

References BackgroundWorkerCancelLocked(), background_worker::lock, vlc_mutex_lock(), and vlc_mutex_unlock().

Referenced by input_preparser_Cancel(), input_preparser_Deactivate(), and vlc_thumbnailer_Cancel().

◆ background_worker_Create()

static struct background_worker* background_worker_Create ( void *  owner,
struct background_worker_config conf 
)
static

◆ background_worker_Delete()

void background_worker_Delete ( struct background_worker worker)

Delete a background-worker.

This function will destroy a background-worker created through background_worker_New. It will effectively stop the currently running task, if any, and empty the queue of pending entities.

Warning
If there is a currently running task, the function will block until it has been stopped.
Parameters
workerthe background-worker

References background_worker_Destroy(), BackgroundWorkerCancelLocked(), background_worker::closing, background_worker::lock, background_worker::nothreads_wait, background_worker::nthreads, background_worker::queue_wait, vlc_cond_broadcast(), vlc_cond_wait(), vlc_mutex_lock(), and vlc_mutex_unlock().

Referenced by input_fetcher_Delete(), input_fetcher_New(), input_preparser_Delete(), and vlc_thumbnailer_Release().

◆ background_worker_Destroy()

static void background_worker_Destroy ( struct background_worker worker)
static

◆ background_worker_New()

struct background_worker* background_worker_New ( void *  owner,
struct background_worker_config config 
)

Create a background-worker.

This function creates a new background-worker using the passed configuration.

Warning
all members of config shall have been set by the caller.
the returned resource must be destroyed using background_worker_Delete on success.
Parameters
ownerthe owner of the background-worker
configthe background-worker's configuration
Returns
a pointer-to the created background-worker on success, NULL on failure.

References background_worker_Create().

Referenced by input_preparser_New(), vlc_thumbnailer_Create(), and WorkerInit().

◆ background_worker_Push()

int background_worker_Push ( struct background_worker worker,
void *  entity,
void *  id,
int  timeout 
)

Push an entity into the background-worker.

This function is used to push an entity into the queue of pending work. The entities will be processed in the order in which they are received (in terms of the order of invocations in a single-threaded environment).

Parameters
workerthe background-worker
entitythe entity which is to be queued
ida value suitable for identifying the entity, or NULL
timeoutthe timeout of the entity in milliseconds, 0 denotes no timeout, a negative value will use the default timeout associated with the background-worker.
Returns
VLC_SUCCESS if the entity was successfully queued, an error-code on failure.

References background_worker::conf, background_worker::lock, background_worker_config::max_threads, background_worker::nthreads, QueuePush(), SpawnThread(), task_Create(), background_worker::uncompleted, unlikely, VLC_ENOMEM, vlc_mutex_lock(), vlc_mutex_unlock(), and VLC_SUCCESS.

Referenced by input_fetcher_Push(), input_preparser_Push(), SearchByScope(), SearchLocal(), and thumbnailer_RequestCommon().

◆ background_worker_RequestProbe()

void background_worker_RequestProbe ( struct background_worker worker)

Request the background-worker to probe the current task.

This function is used to signal the background-worker that it should do another probe to see whether the current task is still alive.

Warning
Note that the function will not wait for the probing to finish, it will simply ask the background worker to recheck it as soon as possible.
Parameters
workerthe background-worker

References background_worker::lock, background_thread::probe, background_thread::probe_cancel_wait, thread, background_worker::threads, vlc_cond_signal(), vlc_list_foreach, vlc_mutex_lock(), and vlc_mutex_unlock().

Referenced by FetcherThread(), on_thumbnailer_input_event(), and OnParserEnded().

◆ BackgroundWorkerCancelLocked()

static void BackgroundWorkerCancelLocked ( struct background_worker worker,
void *  id 
)
static

◆ QueuePush()

static void QueuePush ( struct background_worker worker,
struct task task 
)
static

◆ QueueRemoveAll()

static void QueueRemoveAll ( struct background_worker worker,
void *  id 
)
static

◆ QueueTake()

static struct task* QueueTake ( struct background_worker worker,
int  timeout_ms 
)
static

◆ RemoveThread()

static void RemoveThread ( struct background_thread thread)
static

◆ SpawnThread()

static bool SpawnThread ( struct background_worker worker)
static

◆ task_Create()

static struct task* task_Create ( struct background_worker worker,
void *  id,
void *  entity,
int  timeout 
)
static

◆ task_Destroy()

static void task_Destroy ( struct background_worker worker,
struct task task 
)
static

◆ TerminateTask()

static void TerminateTask ( struct background_thread thread,
struct task task 
)
static

◆ Thread()

static void* Thread ( void *  data)
static