FFmpeg
Data Structures | Macros | Functions
safe_queue.c File Reference
#include <stdio.h>
#include "queue.h"
#include "safe_queue.h"
#include "libavutil/mem.h"
#include "libavutil/avassert.h"
#include "libavutil/thread.h"

Go to the source code of this file.

Data Structures

struct  SafeQueue
 Double-ended queue with mutex locks ensuring data consistency while multithreading. More...
 

Macros

#define DNNCond   char
 

Functions

static int dnn_cond_init (DNNCond *cond, const void *attr)
 
static int dnn_cond_destroy (DNNCond *cond)
 
static int dnn_cond_signal (DNNCond *cond)
 
static int dnn_cond_wait (DNNCond *cond, AVMutex *mutex)
 
SafeQueueff_safe_queue_create (void)
 Create and initialize a SafeQueue instance. More...
 
void ff_safe_queue_destroy (SafeQueue *sq)
 Destroy the SafeQueue instance. More...
 
size_t ff_safe_queue_size (SafeQueue *sq)
 Return the length of the SafeQueue. More...
 
int ff_safe_queue_push_front (SafeQueue *sq, void *v)
 Add data to the head of queue in the SafeQueue after locking mutex. More...
 
int ff_safe_queue_push_back (SafeQueue *sq, void *v)
 Add data to the tail of queue in the SafeQueue after locking mutex. More...
 
void * ff_safe_queue_pop_front (SafeQueue *sq)
 Remove and free first element from the queue in SafeQueue. More...
 

Macro Definition Documentation

◆ DNNCond

#define DNNCond   char

Definition at line 35 of file safe_queue.c.

Function Documentation

◆ dnn_cond_init()

static int dnn_cond_init ( DNNCond cond,
const void *  attr 
)
inlinestatic

Definition at line 36 of file safe_queue.c.

Referenced by ff_safe_queue_create().

◆ dnn_cond_destroy()

static int dnn_cond_destroy ( DNNCond cond)
inlinestatic

Definition at line 37 of file safe_queue.c.

Referenced by ff_safe_queue_destroy().

◆ dnn_cond_signal()

static int dnn_cond_signal ( DNNCond cond)
inlinestatic

◆ dnn_cond_wait()

static int dnn_cond_wait ( DNNCond cond,
AVMutex mutex 
)
inlinestatic

Definition at line 39 of file safe_queue.c.

Referenced by ff_safe_queue_pop_front().

◆ ff_safe_queue_create()

SafeQueue* ff_safe_queue_create ( void  )

Create and initialize a SafeQueue instance.

Returns
Pointer to the SafeQueue
Return values
NULLif initialization fails

Definition at line 52 of file safe_queue.c.

Referenced by dnn_load_model_tf(), and init_model_ov().

◆ ff_safe_queue_destroy()

void ff_safe_queue_destroy ( SafeQueue sq)

Destroy the SafeQueue instance.

It also frees all elements of the queue, destroys the mutex and condition variable.

Definition at line 69 of file safe_queue.c.

Referenced by dnn_free_model_ov(), and dnn_free_model_tf().

◆ ff_safe_queue_size()

size_t ff_safe_queue_size ( SafeQueue sq)

Return the length of the SafeQueue.

Definition at line 80 of file safe_queue.c.

Referenced by dnn_free_model_ov(), and dnn_free_model_tf().

◆ ff_safe_queue_push_front()

int ff_safe_queue_push_front ( SafeQueue sq,
void *  v 
)

Add data to the head of queue in the SafeQueue after locking mutex.

After adding the data, it signals the condition variable and unlocks the mutex. It increases the length of queue in the SafeQueue by one.

Parameters
sqpointer to the SafeQueue
vdata to be added
Returns
The length of the queue
Return values
0if the queue is not initialized
-1if new entry cannot be created

Definition at line 85 of file safe_queue.c.

◆ ff_safe_queue_push_back()

int ff_safe_queue_push_back ( SafeQueue sq,
void *  v 
)

Add data to the tail of queue in the SafeQueue after locking mutex.

After adding the data, it signals the condition variable and unlocks the mutex. It increases the length of queue in the SafeQueue by one.

Parameters
sqpointer to the SafeQueue
vdata to be added
Returns
The length of the queue
Return values
0if the queue is not initialized
-1if new entry cannot be created

Definition at line 95 of file safe_queue.c.

Referenced by dnn_flush_tf(), dnn_load_model_tf(), execute_model_ov(), execute_model_tf(), infer_completion_callback(), and init_model_ov().

◆ ff_safe_queue_pop_front()

void* ff_safe_queue_pop_front ( SafeQueue sq)

Remove and free first element from the queue in SafeQueue.

Before removing, it waits for the condition variable to signal and acquires the mutex. Finally, it signals the condition and unlocks the mutex. It shrinks the length of queue in the SafeQueue by one.

Parameters
sqpointer to the SafeQueue.
Returns
The value of first element as void. If a null pointer or empty queue is passed, it returns NULL

Definition at line 105 of file safe_queue.c.

Referenced by dnn_execute_model_tf(), dnn_flush_tf(), dnn_free_model_ov(), dnn_free_model_tf(), get_output_ov(), and get_output_tf().