VOID CALLBACK Fbt_Startup(PVOID pParam) { assert(pParam == GetFiberData()); Fbt_AfterSwitch(pParam); DoStuff(); Fbt_Exit(); }
void ASocket::listenSocket(){ if(listen(listenfd,maxListeners)==-1){ throw std::runtime_error("failed to listen"); } printf("Listening on: %i", port ); //event loop // signal (SIGINT, handler); signal(SIGCHLD,SIG_IGN); while(1){ int newSockFd; newSockFd = accept(listenfd,(struct sockaddr*)NULL,NULL); if(newSockFd<0) std::cerr << "Error on Accept" << std::endl; int pid = fork(); if(pid <0) std::cerr << "Error on Fork" << std::endl; if(pid ==0){//if pid = zero that means it is the child. close(listenfd);//close the parent file descriptor, we do not need it and then process will wait again. //create an object here to do stuff with the socket DoStuff(newSockFd); exit(0);//exit child process } else close(newSockFd);//there was a problem }//end of while loop close(listenfd); //never happens; }
void CConsumer<T>::ProcessData(void) { while (m_Producer->m_bLoop) { if (m_Producer->m_bConsumerEnable) { if ( (m_CurrentReadBuffer != m_Producer->m_CurrentWriteBuffer) || (m_Producer->m_bProducerEnable == false) ) { if ( ! m_Producer->m_Data[m_CurrentReadBuffer].empty() ) { m_ProcessedData[m_CurrentReadBuffer].push( DoStuff(m_Producer->m_Data[m_CurrentReadBuffer].front()) ); m_Producer->m_Data[m_CurrentReadBuffer].pop(); m_TotalProcessed++; } else { if (m_CurrentReadBuffer == (BUFFER_COUNT-1)) m_CurrentReadBuffer = 0; else { m_CurrentReadBuffer++; } } } if ( (m_Producer->m_bProducerEnable == false) && (m_Producer->m_TotalRead == m_TotalProcessed) ) { cout << "Total Processed: " << m_TotalProcessed << endl; m_Producer->m_bConsumerEnable = false; } } std::this_thread::sleep_for(std::chrono::milliseconds(1)); } }