lib: fixed missing endian adjustment in bookmark parser
[barry.git] / src / dataqueue.h
blob1f154dc23e8b94c18b80bc50ea1292b07758c616
1 ///
2 /// \file dataqueue.h
3 /// FIFO queue of Data objects
4 ///
6 /*
7 Copyright (C) 2007-2010, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #ifndef __BARRY_DATAQUEUE_H__
23 #define __BARRY_DATAQUEUE_H__
25 #include <queue>
26 #include <pthread.h>
28 namespace Barry {
30 class Data;
33 // DataQueue class
35 /// This class provides a thread aware fifo queue for Data objects,
36 /// providing memory management for all Data object pointers it contains.
37 ///
38 /// It uses similar member names as std::queue<>, for consistency.
39 ///
40 class DataQueue
42 typedef std::queue<Data*> queue_type;
44 pthread_mutex_t m_waitMutex;
45 pthread_cond_t m_waitCond;
47 mutable pthread_mutex_t m_accessMutex; // locked for each access of m_queue
49 queue_type m_queue;
51 public:
52 DataQueue();
53 ~DataQueue(); // frees all data in the queue
55 // Pushes data into the end of the queue.
56 // The queue owns this pointer as soon as the function is
57 // called. In the case of an exception, it will be freed.
58 // Performs a thread broadcast once new data has been added.
59 void push(Data *data);
61 // Pops the next element off the front of the queue.
62 // Returns 0 if empty.
63 // The queue no longer owns this pointer upon return.
64 Data* pop();
66 // Pops the next element off the front of the queue, and
67 // waits until one exists if empty. If still no data
68 // on timeout, returns null.
69 // Timeout specified in milliseconds. Default is wait forever.
70 Data* wait_pop(int timeout = -1);
72 // Pops all data from other and appends it to this.
73 // After calling this function, other will be empty, and
74 // this will contain all its data.
75 // In the case of an exception, any uncopied data will
76 // remain in other.
77 void append_from(DataQueue &other);
79 bool empty() const; // return true if empty
80 size_t size() const;
83 } // namespace Barry
85 #endif