国产探花免费观看_亚洲丰满少妇自慰呻吟_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);

}


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

圖片精選

主站蜘蛛池模板: 平定县| 深州市| 彰化市| 和硕县| 莲花县| 双城市| 临泉县| 藁城市| 治多县| 宜春市| 凉山| 湘潭县| 济阳县| 股票| 称多县| 淮北市| 来宾市| 石河子市| 株洲市| 杭州市| 桐庐县| 鹰潭市| 永城市| 中牟县| 汶川县| 平谷区| 英吉沙县| 嘉荫县| 嘉义市| 云龙县| 镇远县| 宣城市| 台东县| 滁州市| 西乌珠穆沁旗| 江口县| 文水县| 宜丰县| 广水市| 高雄市| 根河市|