-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue_abstract.h
77 lines (62 loc) · 1.46 KB
/
queue_abstract.h
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
作者:Piovano
日期:2014.05.26
版本:1.0
描述:抽象队列
*/
#ifndef _QUEUE_ABSTRACT_H
#define _QUEUE_ABSTRACT_H
#include <iostream>
#include <string>
#include <stdlib.h>
#include <unistd.h>
#include <semaphore.h>
#include <pthread.h>
#include <fcntl.h>
#include <time.h>
#include <errno.h>
#include "queue_common.h"
/*
类名:抽象队列(有类型)
功能:入队、出队、获取队列长度
*/
template<class T>
class AbstractQueue {
protected:
off_t _dataSize;
sem_t _semPop;
virtual int doPush(T *pointer, bool block) = 0;
virtual int doPop(T *&pointer, bool block) = 0;
void create(T *&pointer);
void destroy(T *pointer);
public:
AbstractQueue(off_t dataSize);
~AbstractQueue();
int push(T *pointer, bool block = true);
int pop(T *&pointer, bool block = true);
unsigned long length();
off_t dataSize();
};
/*
类名:抽象队列(无类型)
功能:入队、出队、获取队列长度
*/
template<>
class AbstractQueue<void> {
protected:
sem_t _semPop;
virtual int doPush(void *pointer, off_t size, bool block) = 0;
virtual int doPop(void *&pointer, off_t &size, bool block) = 0;
void create(void *&pointer, size_t size);
void destroy(void *pointer);
public:
AbstractQueue();
~AbstractQueue();
int push(void *pointer, off_t size, bool block = true);
int pop(void *&pointer, off_t &size, bool block = true);
unsigned long length();
};
#ifndef _QUEUE_ABSTRACT_C
#include "queue_abstract.cpp"
#endif
#endif