Mqueue.h
#ifndef MQUEUE_H
#define MQUEUE_H
#include <vector>
#include<mutex> //加锁的头文件
#define LEN 10
//mutex m;
//一级 >128字节 系统申请
//二级 <128字节 内存管理
//内存池
template<typename T>
class Mqueue
{
public:
class Node;
Mqueue()
{
_head = new Node();
_head->_next = NULL;
_tail = _head;
}
~Mqueue()
{
while(!isEmpty())
{
pop();
}
delete _head;
_head = _tail = NULL;
}
void push(T val)
{
_tail->_next = new Node(val); //申请内存
_tail = _tail->_next;
_tail->_next = NULL;
}
void pop()
{
if(isEmpty())
{
throw "queue is empty"; //抛出异常
}
Node *tmp = _head->_next;
_head->_next = _head->_next->_next;
if(_head->_next == NULL)
{
_tail = _head;
}
delete tmp;
}
T top()
{
return _head->_next->_val;
}
bool isEmpty()
{
return _head == _tail;
}
private:
class space
{
public:
static space* getSpace()
{
if(_space == NULL)
{