Muduo庫原始碼分析(6) 有界緩衝區,無界緩衝區

2021-08-05 19:40:32 字數 1114 閱讀 8596

class boundedblockingqueue : noncopyable

void put(const t& x)

assert(!queue_.full());

queue_.push_back(x);

notempty_.notify();

} t take()

assert(!queue_.empty());

t front(queue_.front());

queue_.pop_front();

notfull_.notify();

return front;

} bool empty() const

bool full() const

size_t size() const

size_t capacity() const

private:

mutable mutexlock mutex_;// 互斥量

condition notempty_;// 條件變數表明可消費的數量

condition notfull_;// 條件變數表明可生產的數量

circular_bufferqueue_;// 環形緩衝區

};

無界緩衝區

class blockingqueue : noncopyable

void put(const t& x)

void put(t&& x)

t take()

assert(!queue_.empty());

t front(std::move(queue_.front()));

queue_.pop_front();

return front;

} size_t size() const

private:

mutable mutexlock mutex_;// 互斥量

condition notempty_;// 條件變數表明可消費的數量

std::deque

queue_;// 佇列

};

muduo 原始碼分析(前言0)

前言0 個人高效能 高併發linux伺服器端程式設計 網路程式設計 比較感興趣,自己寫過一些簡單的tcp通訊程式,用程序池實現簡單cgi伺服器,用執行緒池實現簡單web伺服器。熟悉c 程式語言,但是沒有用c 參與過乙個專案,所以想尋找乙個開源專案,用c 自己實現乙個相對完整的網路庫,所以選擇了mud...

muduo庫原始碼學習 base Logfile

本檔案使用的是c 17版本 ifndef muduo base logfile h define muduo base logfile h include include include namespace muduo class logfile noncopyable 檔案日誌類 endif mu...

Muduo原始碼分析(2) 原子類

如果 ptr oldval,就將newval寫入 ptr,然後返回 ptr 否則直接返回 ptr sync val compare and swap type ptr,type oldval type newval,返回修改前的值 sync fetch and add type ptr,type v...