当前位置: 首页>>代码示例>>C++>>正文


C++ BoundedBuffer类代码示例

本文整理汇总了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);
}
开发者ID:paddor,项目名称:cpp-advanced-exercises,代码行数:7,代码来源:bounded_buffer_content_suite.cpp

示例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();
}
开发者ID:killbug2004,项目名称:WSProf,代码行数:28,代码来源:IntelligentDocInfo.cpp

示例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());
}
开发者ID:paddor,项目名称:cpp-advanced-exercises,代码行数:7,代码来源:bounded_buffer_content_suite.cpp

示例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);
}
开发者ID:paddor,项目名称:cpp-advanced-exercises,代码行数:7,代码来源:bounded_buffer_content_suite.cpp

示例5: consumer_run

void* consumer_run(void *arg) {
    while (true) {
        BoundedBuffer* buffer = (BoundedBuffer*) arg;
        int val = buffer->get();
        sleep(2);
    }
}
开发者ID:gaoshuaifu,项目名称:kungfu,代码行数:7,代码来源:MultiThreadBoundedBuffer.cpp

示例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());
}
开发者ID:paddor,项目名称:cpp-advanced-exercises,代码行数:7,代码来源:bounded_buffer_content_suite.cpp

示例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"));
}
开发者ID:killbug2004,项目名称:WSProf,代码行数:8,代码来源:TestBoundedBuffer.cpp

示例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);
}
开发者ID:paddor,项目名称:cpp-advanced-exercises,代码行数:10,代码来源:bounded_buffer_content_suite.cpp

示例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);
    }
}
开发者ID:gaoshuaifu,项目名称:kungfu,代码行数:10,代码来源:MultiThreadBoundedBuffer.cpp

示例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));
    }
}
开发者ID:jon-engelbert,项目名称:concurrent-solutions,代码行数:7,代码来源:con_prod.cpp

示例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));
    }
}
开发者ID:jon-engelbert,项目名称:concurrent-solutions,代码行数:7,代码来源:con_prod.cpp

示例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"));
}
开发者ID:killbug2004,项目名称:WSProf,代码行数:18,代码来源:TestBoundedBuffer.cpp

示例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);
}
开发者ID:paddor,项目名称:cpp-advanced-exercises,代码行数:23,代码来源:bounded_buffer_content_suite.cpp

示例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());
}
开发者ID:paddor,项目名称:cpp-advanced-exercises,代码行数:6,代码来源:bounded_buffer_make_buffer_suite.cpp

示例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());
}
开发者ID:paddor,项目名称:cpp-advanced-exercises,代码行数:6,代码来源:bounded_buffer_content_suite.cpp


注:本文中的BoundedBuffer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。