From 25de5e761daab8b897a4f09ff8503e6f43c299f9 Mon Sep 17 00:00:00 2001 From: Uros Majstorovic Date: Wed, 3 May 2017 21:10:08 +0200 Subject: initial commit --- code/msgq.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 code/msgq.h (limited to 'code/msgq.h') diff --git a/code/msgq.h b/code/msgq.h new file mode 100644 index 0000000..0bf47b3 --- /dev/null +++ b/code/msgq.h @@ -0,0 +1,32 @@ +#ifdef ECP_WITH_PTHREAD + +#include +#include + +#define ECP_MAX_CONN_MSG 8 +#define ECP_ERR_MAX_CONN_MSG -100 + +struct ECPConnection; + +typedef struct ECPMessage { + unsigned char payload[ECP_MAX_PKT]; + ssize_t size; +} ECPMessage; + +typedef struct ECPConnMsgQ { + unsigned short empty_idx; + unsigned short occupied[ECP_MAX_CONN_MSG]; + unsigned short w_idx[ECP_MAX_PTYPE]; + unsigned short r_idx[ECP_MAX_PTYPE]; + unsigned short msg_idx[ECP_MAX_PTYPE][ECP_MAX_CONN_MSG+1]; + ECPMessage msg[ECP_MAX_CONN_MSG]; + pthread_mutex_t mutex; + pthread_cond_t cond[ECP_MAX_PTYPE]; +} ECPConnMsgQ; + +int ecp_conn_msgq_create(struct ECPConnection *conn); +void ecp_conn_msgq_destroy(struct ECPConnection *conn); +ssize_t ecp_conn_msgq_push(struct ECPConnection *conn, unsigned char *payload, size_t payload_size); +ssize_t ecp_conn_msgq_pop(struct ECPConnection *conn, unsigned char ptype, unsigned char *payload, size_t payload_size, unsigned int timeout); + +#endif /* ECP_WITH_PTHREAD */ \ No newline at end of file -- cgit v1.2.3