Project

General

Profile

Statistics
| Revision:

root / include / libwireless / queue.h @ 1554

History | View | Annotate | Download (2.43 KB)

1
/**
2
 * Copyright (c) 2007 Colony Project
3
 * 
4
 * Permission is hereby granted, free of charge, to any person
5
 * obtaining a copy of this software and associated documentation
6
 * files (the "Software"), to deal in the Software without
7
 * restriction, including without limitation the rights to use,
8
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9
 * copies of the Software, and to permit persons to whom the
10
 * Software is furnished to do so, subject to the following
11
 * conditions:
12
 * 
13
 * The above copyright notice and this permission notice shall be
14
 * included in all copies or substantial portions of the Software.
15
 * 
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
 * OTHER DEALINGS IN THE SOFTWARE.
24
 **/
25

    
26
/**
27
 * @file queue.h
28
 * @brief A queue implementation
29
 * 
30
 * Implements a queue, a first in, first out data structure.
31
 *
32
 * @author Brian Coltin, Colony Project, CMU Robotics Club
33
 **/
34

    
35
#ifndef WIRELESS_QUEUE_H
36
#define WIRELESS_QUEUE_H
37

    
38
#ifndef ROBOT
39
#include <pthread.h>
40
#endif
41

    
42
struct node_def;
43

    
44
/**
45
 * @defgroup queue Queue
46
 * @brief A queue implementation
47
 * 
48
 * A queue implementation.
49
 *
50
 * @{
51
 **/
52

    
53
/**
54
 * @struct Queue
55
 * Represents a queue, a first in, first out data structure.
56
 **/
57
typedef struct
58
{
59
        /**
60
         * The head of the queue, the next item to be removed.
61
         **/
62
        struct node_def* head;
63
        /**
64
         * The tail of the queue, the last item added.
65
         **/
66
        struct node_def* tail;
67
        /**
68
         * The number of elements in the queue.
69
         **/
70
        int size;
71
        
72
#ifndef ROBOT
73
        pthread_mutex_t lock;
74
#endif
75
} Queue;
76

    
77
/** @brief Create a new queue **/
78
Queue* queue_create(void);
79
/** @brief Destroy a queue **/
80
void queue_destroy(Queue* q);
81
/** @brief Add an element to a queue **/
82
int queue_add(Queue* q, void* item);
83
/** @brief Remove an element from a queue **/
84
void* queue_remove(Queue* q);
85
/** @brief Remove all instances of a given element from a queue **/
86
void queue_remove_all(Queue* q, void* item);
87
/** @brief Get the size of a queue **/
88
int queue_size(Queue* q);
89
/** @brief Check if the queue is empty **/
90
int queue_is_empty(Queue* q);
91

    
92
/** @} **/
93

    
94

    
95
#endif