myMPD
Internal API documentation
Loading...
Searching...
No Matches
msg_queue.h File Reference

Message queue implementation. More...

#include "src/lib/api.h"
#include <pthread.h>
#include <stdbool.h>
#include <time.h>
Include dependency graph for msg_queue.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  t_mympd_msg
 
struct  t_mympd_queue
 

Enumerations

enum  mympd_queue_types { QUEUE_TYPE_REQUEST , QUEUE_TYPE_RESPONSE }
 

Functions

struct t_mympd_queuemympd_queue_create (const char *name, enum mympd_queue_types type, bool event)
 
void * mympd_queue_free (struct t_mympd_queue *queue)
 
bool mympd_queue_push (struct t_mympd_queue *queue, void *data, unsigned id)
 
void * mympd_queue_shift (struct t_mympd_queue *queue, int timeout_ms, unsigned id)
 
int mympd_queue_expire_age (struct t_mympd_queue *queue, time_t max_age_s)
 

Detailed Description

Message queue implementation.

Enumeration Type Documentation

◆ mympd_queue_types

Queue types

Enumerator
QUEUE_TYPE_REQUEST 

queue holds only t_work_request entries

QUEUE_TYPE_RESPONSE 

queue holds only t_work_response entries

Function Documentation

◆ mympd_queue_create()

struct t_mympd_queue * mympd_queue_create ( const char *  name,
enum mympd_queue_types  type,
bool  event 
)

Creates a thread safe message queue

Parameters
namedescription of the queue
typetype of the queue QUEUE_TYPE_REQUEST or QUEUE_TYPE_RESPONSE
eventcreate an eventfd?
Returns
pointer to allocated and initialized queue struct

◆ mympd_queue_expire_age()

int mympd_queue_expire_age ( struct t_mympd_queue queue,
time_t  max_age_s 
)

Expire entries from the queue by age

Parameters
queuepointer to the queue
max_age_smax age of nodes in seconds
Returns
number of expired nodes

◆ mympd_queue_free()

void * mympd_queue_free ( struct t_mympd_queue queue)

Frees all queue nodes and the queue itself

Parameters
queuepointer to the queue
Returns
NULL

◆ mympd_queue_push()

bool mympd_queue_push ( struct t_mympd_queue queue,
void *  data,
unsigned  id 
)

Appends data to the queue

Parameters
queuepointer to the queue
datastruct t_work_request or t_work_response
idid of the queue entry
Returns
true on success else false

◆ mympd_queue_shift()

void * mympd_queue_shift ( struct t_mympd_queue queue,
int  timeout_ms,
unsigned  id 
)

Gets the first entry or the entry with specific id

Parameters
queuepointer to the queue
timeout_mstimeout in ms to wait for a queue entry, 0 to wait infinite -1 for no wait
id0 for first entry or specific id
Returns
t_work_request or t_work_response