pthread_queue.h
Go to the documentation of this file.
1 /*
2 Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
3 Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
4 Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
5 
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
10 
11 This library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
15 
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 
21 /*
22 Inspired by c-pthread-queue by Matthew Dickinson
23 http://code.google.com/p/c-pthread-queue/
24 */
25 
26 #ifndef _PTHREAD_QUEUE_H_
27 #define _PTHREAD_QUEUE_H_
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #include <stdlib.h>
34 #include <stdint.h>
35 #include <sys/time.h>
36 
37 #include <csp/arch/csp_queue.h>
38 
39 #define PTHREAD_QUEUE_ERROR CSP_QUEUE_ERROR
40 #define PTHREAD_QUEUE_EMPTY CSP_QUEUE_ERROR
41 #define PTHREAD_QUEUE_FULL CSP_QUEUE_ERROR
42 #define PTHREAD_QUEUE_OK CSP_QUEUE_OK
43 
44 typedef struct pthread_queue_s {
45  void * buffer;
46  int size;
47  int item_size;
48  int items;
49  int in;
50  int out;
51  pthread_mutex_t mutex;
52  pthread_cond_t cond_full;
53  pthread_cond_t cond_empty;
55 
56 pthread_queue_t * pthread_queue_create(int length, size_t item_size);
58 int pthread_queue_enqueue(pthread_queue_t * queue, void * value, uint32_t timeout);
59 int pthread_queue_dequeue(pthread_queue_t * queue, void * buf, uint32_t timeout);
61 
62 #ifdef __cplusplus
63 } /* extern "C" */
64 #endif
65 
66 #endif // _PTHREAD_QUEUE_H_
67 
Definition: pthread_queue.h:44
pthread_queue_t * pthread_queue_create(int length, size_t item_size)
struct pthread_queue_s pthread_queue_t
int size
Definition: pthread_queue.h:46
pthread_cond_t cond_empty
Definition: pthread_queue.h:53
int pthread_queue_dequeue(pthread_queue_t *queue, void *buf, uint32_t timeout)
pthread_cond_t cond_full
Definition: pthread_queue.h:52
int pthread_queue_enqueue(pthread_queue_t *queue, void *value, uint32_t timeout)
pthread_mutex_t mutex
Definition: pthread_queue.h:51
int in
Definition: pthread_queue.h:49
int items
Definition: pthread_queue.h:48
void pthread_queue_delete(pthread_queue_t *q)
int item_size
Definition: pthread_queue.h:47
int pthread_queue_items(pthread_queue_t *queue)
int out
Definition: pthread_queue.h:50
void * buffer
Definition: pthread_queue.h:45