国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > C++ > 正文

c++自定義隊列

2019-11-08 01:06:09
字體:
來源:轉載
供稿:網友
#ifndef BLOCKINGQUEUE_H_#define BLOCKINGQUEUE_H_#include <list>#include <vector>#include <queue>#include <utils/Mutex.h>#include <semaphore.h>#include <utils/Condition.h>#define DISALLOW_COPY_AND_ASSIGN(TypeName) /    TypeName(const TypeName&);                /    TypeName& Operator=(const TypeName&)namespace android {template<typename T, int count>class BlockingQueue {PRivate:    mutable std::list<T> mList;    mutable Mutex mLock;    mutable Condition mContentAvailableCondition;//volatile int m_size;    T front(bool remove) {        Mutex::Autolock autolock(mLock);        while ( mList.empty() ) {int ret =0;           ret = mContentAvailableCondition.waitRelative(mLock, 200000000);  //m_size = mList.size(); // ALOGD("wujw %s %d %lld %d %d %d %d /n", __FUNCTION__, __LINE__, m_size, &m_size, ret, mList.empty(), gettid());        }        T e = *(mList.begin());        if (remove) {            mList.erase(mList.begin());        }        return e;    }    DISALLOW_COPY_AND_ASSIGN(BlockingQueue);public:    BlockingQueue() {    }    ~BlockingQueue() {    }    bool empty() {        Mutex::Autolock autolock(mLock);        return mList.empty();    }    int size() {        Mutex::Autolock autolock(mLock);        return mList.size();    }    void clear() {        Mutex::Autolock autolock(mLock);        mList.clear();    }    T peek() {        return front(false);    }    T pop() {//ALOGD("wujw %s %d /n", __FUNCTION__, __LINE__);        return front(true);    }    void push(T e) {        Mutex::Autolock autolock(mLock);if(mList.size( ) <= count){        mList.push_back(e);//ALOGD("wujw %s %d %d /n", __FUNCTION__, __LINE__,mList.size( ));}//m_size = mList.size( );//ALOGD("wujw %s %d %d %lld %d /n", __FUNCTION__, __LINE__,m_size,&m_size,gettid());        mContentAvailableCondition.signal();    }};

} /* namespace android */

#endif

typedef struct{

char buf[100];

int nLen;

}TestData;

class Test{

BlockingQueue<TestData, 20>  testQueue;

};

readDataThread()

{

TestData testdata;

ret = read(fd,testdata.buf,len);

testdata.nLen = ret;

pThis->testQueue.push(testdata);

}

sendDataThread()

{

TestData testdata;

pThis->testQueue.pop(testdata);

ret = write(fd,testdata.buf,testdata.nLen);

}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 光山县| 靖州| 松溪县| 陆河县| 同仁县| 卓尼县| 霞浦县| 常宁市| 凉山| 二连浩特市| 库尔勒市| 越西县| 新晃| 溆浦县| 淮滨县| 镇赉县| 鞍山市| 定安县| 刚察县| 塔河县| 罗田县| 精河县| 根河市| 依安县| 垦利县| 昌都县| 顺平县| 岳阳县| 和平县| 微山县| 兴和县| 临城县| 迁西县| 牡丹江市| 朝阳县| 乐都县| 酉阳| 安义县| 东平县| 安丘市| 三明市|