You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.5 KiB
C
58 lines
1.5 KiB
C
10 years ago
|
/*
|
||
|
* This is a proprietary software. See COPYING for further details.
|
||
|
*
|
||
|
* (c) 2013 Copyright Askele, inc. <http://askele.com>
|
||
|
* (c) 2013 Copyright Askele Ingria, inc. <http://askele-ingria.com>
|
||
|
* (c) 2014 Copyright Confident, inc. (granted permission to use in commercial software)
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @file pth_queue.h
|
||
|
* @author Alexander Vdolainen
|
||
|
* @date 4 Nov 2013
|
||
|
* @brief queue implementation for threads intercommunication
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#ifndef __PTH_QUEUE_H__
|
||
|
#define __PTH_QUEUE_H__
|
||
|
|
||
|
#include <pthread.h>
|
||
|
|
||
|
#define SYS_MSG 0x0f0affee
|
||
|
#define USR_MSG 0x0afeeffe
|
||
|
#define NIL_MSG 0x0
|
||
|
|
||
|
typedef struct pth_msg_s {
|
||
|
void *data; /** < message payload */
|
||
|
unsigned int msgtype; /** < message type ID */
|
||
|
unsigned int qlength; /** < current queue length (actual on add moment),
|
||
|
* it makes no sense with few readers */
|
||
|
usrtc_node_t node;
|
||
|
} pth_msg_t;
|
||
|
|
||
|
typedef struct pth_queue_s {
|
||
|
unsigned int length;
|
||
|
/* sync */
|
||
|
pthread_mutex_t mutex;
|
||
|
pthread_cond_t cond;
|
||
|
/* queue data */
|
||
|
usrtc_t qtree;
|
||
|
/* cache */
|
||
|
usrtc_t msgcache;
|
||
|
} pth_queue_t;
|
||
|
|
||
|
int pth_queue_init(pth_queue_t *queue);
|
||
|
|
||
|
int pth_queue_add(pth_queue_t *queue, void *data, unsigned int msgtype);
|
||
|
|
||
|
int pth_queue_get(pth_queue_t *queue, const struct timespec *timeout,
|
||
|
pth_msg_t *msg);
|
||
|
|
||
|
unsigned int pth_queue_length(pth_queue_t *queue);
|
||
|
|
||
|
int pth_queue_destroy(pth_queue_t *queue, int freedata,
|
||
|
void (*free_msg)(void *));
|
||
|
|
||
|
#endif /* __PTH_QUEUE_H__ */
|