void ByteBufferAsyncProcessor::ThreadProc()

in rd-cpp/src/rd_framework_cpp/src/main/wire/ByteBufferAsyncProcessor.cpp [137:184]


void ByteBufferAsyncProcessor::ThreadProc()
{
	rd::util::set_thread_name(id.empty() ? "ByteBufferAsyncProcessor Thread" : id.c_str());
	async_thread_id = std::this_thread::get_id();

	while (true)
	{
		{
			std::lock_guard<decltype(lock)> guard(lock);

			if (state >= StateKind::Terminated)
			{
				return;
			}

			while ((data.empty() && queue.empty()) || interrupt_balance != 0)
			{
				if (state >= StateKind::Stopping)
				{
					return;
				}
				cv.wait(lock);

				logger->debug("{}'s ThreadProc waited for notify", id);

				if (state >= StateKind::Terminating)
				{
					return;
				}
			}

			if (!data.empty())
			{
				add_data(std::move(data));
				data.clear();
			}
		}

		try
		{
			process();
		}
		catch (std::exception const& e)
		{
			logger->error("Exception while processing byte queue | {}", e.what());
		}
	}
}