-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopq.hpp
59 lines (42 loc) · 1.01 KB
/
opq.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef OPQ_HPP
#define OPQ_HPP
#include <pthread.h>
#include <sys/types.h>
#include "mutexobj.hpp"
template <class T>
class QueueElement
{
public:
QueueElement<T> *prev, *next;
T *element;
QueueElement<T>( T *s ) { element = s; }
};
template <class T>
class Queue
{
private:
uint num_ops;
pthread_mutex_t mutex;
pthread_cond_t read_activity;
pthread_cond_t write_activity;
int count, max_size;
QueueElement<T> *head, *tail;
Queue<T> *output;
void (*enqueue_callback)(void *obj);
void *obj;
public:
Queue( int s_max_size );
Queue() { Queue( 0 ); }
~Queue();
QueueElement<T> *enqueue( T *h );
QueueElement<T> *leapfrog_enqueue( T *h, T *leapfrog_type );
void remove_specific( QueueElement<T> *op );
T *dequeue( bool wait );
void flush_type( T *h );
void flush( void );
int get_count( void ) { MutexLock x( &mutex ); return count; }
void hookup( Queue<T> *s_output );
void set_enqueue_callback( void (*s_enqueue_callback)(void *obj),
void *s_obj );
};
#endif