本文整理汇总了C++中BoundedBuffer类的典型用法代码示例。如果您正苦于以下问题:C++ BoundedBuffer类的具体用法?C++ BoundedBuffer怎么用?C++ BoundedBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BoundedBuffer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_const_buffer_back_throws_after_push_pop
void test_const_buffer_back_throws_after_push_pop() {
BoundedBuffer<int> buffer { 5 };
buffer.push(5);
buffer.pop();
auto const & constBuffer = buffer;
ASSERT_THROWS(constBuffer.back(), std::logic_error);
}
示例2: LoadIntelligentDocumentInfo
void IntelligentDocInfo::LoadIntelligentDocumentInfo()
{
m_vHashRevision.clear();
BoundedBuffer buf = m_DocumentStore.ReadDataBlock(INTELLIGENT_DOC_INFO_VER_1);
if(buf.GetMaxSize() == 0)
return;
int iPos(0);
while (iPos < HASH_ENTRY_TABLE_SIZE)
{
int iHashCode = buf.ReadIntAt(iPos);
iPos += sizeof(int);
int iRevisionNumber = buf.ReadIntAt(iPos);
iPos += sizeof(int);
HashRevPair hrPair;
hrPair.first = iHashCode;
hrPair.second = iRevisionNumber;
if(hrPair.first != 0)
m_vHashRevision.push_back(hrPair);
else
iPos = HASH_ENTRY_TABLE_SIZE;
}
LoadReplyInfo();
}
示例3: test_const_buffer_back_gets_last_element_of_two_pushs
void test_const_buffer_back_gets_last_element_of_two_pushs() {
BoundedBuffer<int> buffer { 5 };
buffer.push(1);
buffer.push(2);
auto const & constBuffer = buffer;
ASSERT_EQUAL(2, constBuffer.back());
}
示例4: test_const_buffer_front_throws_after_push_pop
void test_const_buffer_front_throws_after_push_pop() {
BoundedBuffer<int, 5> buffer { };
buffer.push(5);
buffer.pop();
auto const & constBuffer = buffer;
ASSERT_THROWS(constBuffer.front(), std::logic_error);
}
示例5: consumer_run
void* consumer_run(void *arg) {
while (true) {
BoundedBuffer* buffer = (BoundedBuffer*) arg;
int val = buffer->get();
sleep(2);
}
}
示例6: test_const_buffer_front_gets_first_element_of_pushs
void test_const_buffer_front_gets_first_element_of_pushs() {
BoundedBuffer<int> buffer { 5 };
buffer.push(1);
buffer.push(2);
auto const & constBuffer = buffer;
ASSERT_EQUAL(1, constBuffer.front());
}
示例7: buf
void TestBoundedBuffer::TestReadBuffer()
{
BoundedBuffer buf (NULL, 10);
buf.WriteStringAt(0, _T("abc"), 3);
BoundedBuffer newbuf(buf.ReadBufferAt(0, 3));
assertMessage(newbuf.m_iMaxSize == 3, _T("Failed to read the buffer"));
assertMessage(newbuf.ReadStringAt(0, 3) == _T("abc"), _T("Failed to read the buffer"));
}
示例8: test_buffer_after_swap_argument_has_this_content
void test_buffer_after_swap_argument_has_this_content() {
std::vector<int> frontValues { }, expectedValues { 1, 2, 3 };
BoundedBuffer<int> buffer { 5 }, otherBuffer { 5 };
buffer.push(1);
buffer.push(2);
buffer.push(3);
buffer.swap(otherBuffer);
3_times([&]() {frontValues.push_back(otherBuffer.front()); otherBuffer.pop();});
ASSERT_EQUAL(expectedValues, frontValues);
}
示例9: producer_run
void* producer_run(void* arg){
BoundedBuffer* buffer = (BoundedBuffer*) arg;
string s = "0123456789";
int i = 0;
while(true){
buffer->put(s[i] - '0');
i = (i + 1) % 10;
sleep(1);
}
}
示例10: producer
void producer(int id, BoundedBuffer& buffer){
for(int i = 0; i < 75; ++i){
buffer.deposit(i);
std::cout << "Produced " << id << " produced " << i << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
}
示例11: consumer
void consumer(int id, BoundedBuffer& buffer){
for(int i = 0; i < 50; ++i){
int value = buffer.fetch();
std::cout << "Consumer " << id << " fetched " << value << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(250));
}
}
示例12: master
void TestBoundedBuffer::TestWriteBuffer()
{
unsigned char MasterBuf [100];
unsigned char NotMasterBuf [200];
BoundedBuffer master (MasterBuf, 100);
BoundedBuffer smaller (NotMasterBuf, 50);
BoundedBuffer bigger (NotMasterBuf, 200);
master.ClearBuffer();
smaller.ClearBuffer();
smaller.WriteStringAt(0, _T("Hello Smaller"), 13);
master.WriteBufferAt(0, smaller);
assertMessage(CStdString((char*)(master.m_pBuf)) == _T("Hello Smaller"), _T("Failed to write the buffer"));
assertThrows(master.WriteBufferAt(0, bigger), Workshare::Exception);
assertMessage(CStdString((char*)(master.m_pBuf)) == _T("Hello Smaller"), _T("The buffer should throw without changing state if the incomming buffer is too large"));
}
示例13: test_buffer_fronts_in_sequence_of_push_pop
void test_buffer_fronts_in_sequence_of_push_pop() {
BoundedBuffer<int> buffer { 5 };
std::vector<int> frontValues { }, expectedValues { 1, 1, 1, 2, 2, 3, 4, 4, 5 };
buffer.push(1);
frontValues.push_back(buffer.front());
buffer.push(2);
frontValues.push_back(buffer.front());
buffer.push(3);
frontValues.push_back(buffer.front());
buffer.pop();
frontValues.push_back(buffer.front());
buffer.push(4);
frontValues.push_back(buffer.front());
buffer.pop();
frontValues.push_back(buffer.front());
buffer.pop();
frontValues.push_back(buffer.front());
buffer.push(5);
frontValues.push_back(buffer.front());
buffer.pop();
frontValues.push_back(buffer.front());
ASSERT_EQUAL(expectedValues, frontValues);
}
示例14: test_make_bounded_buffer_from_two_mixed_arguments_second_element_moved
void test_make_bounded_buffer_from_two_mixed_arguments_second_element_moved() {
MemoryOperationCounter expected{1, 0, true};
MemoryOperationCounter lvalue{};
BoundedBuffer<MemoryOperationCounter> buffer = BoundedBuffer<MemoryOperationCounter>::make_buffer(lvalue, MemoryOperationCounter{});
ASSERT_EQUAL(expected, buffer.back());
}
示例15: test_const_buffer_back_gets_element_of_push
void test_const_buffer_back_gets_element_of_push() {
BoundedBuffer<int> buffer { 5 };
buffer.push(5);
auto const & constBuffer = buffer;
ASSERT_EQUAL(5, constBuffer.back());
}