예제 #1
0
파일: 4-3.c 프로젝트: shubmit/shub-ltp
void main_loop()
{
	int child_count = 0;
	int stat_pipe[2];
	int ret;
	int status;
	pid_t child;
	unsigned long usec_start, usec;
	unsigned long child_count_sig;

	usec_start = current_time_usec();
	do {
		SAFE(pipe(stat_pipe));

		child_count++;
		count_ope += NSCENAR;
		fflush(stdout);
		child = fork();
		if (child == 0) {
			close(stat_pipe[0]);
			do_child();
			SAFE(write(stat_pipe[1], &count_sig,
				sizeof(count_sig)));
			close(stat_pipe[1]);
			pthread_exit(0);
			UNRESOLVED(0, "Should not be reached");
			exit(0);
		}
		close(stat_pipe[1]);
		SAFE(read(stat_pipe[0], &child_count_sig, sizeof(count_sig)));
		close(stat_pipe[0]);
		count_sig += child_count_sig;

		ret = waitpid(child, &status, 0);
		if (ret != child)
			UNRESOLVED(errno, "Waitpid returned the wrong PID");

		if (!WIFEXITED(status)) {
			output("status: %d\n", status);
			FAILED("Child exited abnormally");
		}

		if (WEXITSTATUS(status) != 0) {
			output("exit status: %d\n", WEXITSTATUS(status));
			FAILED("An error occured in child");
		}

		usec = current_time_usec();
	} while ((usec - usec_start) < RUN_TIME_USEC);
	output("Test spawned %d child processes.\n", child_count);
	output("Test finished after %lu usec.\n", usec - usec_start);
}
예제 #2
0
/**
* brief:
*
* @returns   
*/
void RespProcessor::doIt()
{
	char buffer[16*1024] = {'\0'};

	ResponseManager* pRespMgr = ResponseManager::getInstance();
	assert(NULL != pRespMgr);
	
	while(true)
	{
		CmdTask resp;
		bool ret = pRespMgr->getRespTask(resp);
		if(!ret)
		{
			LOG4CPLUS_WARN(CLogger::logger, "response array is empty.");
			continue;
		}

		SessionBase* pSession = _sess_mgr_prt->getSession(resp.seqno);
		if(NULL == pSession)
		{
			LOG4CPLUS_ERROR(CLogger::logger, "can't find the session by " << resp.seqno);
			delete resp.pCmd;
			resp.pCmd = NULL;
			continue;
		}

		int64_t uid = resp.pCmd->get_userid();
		string name = resp.pCmd->get_cmd_name();
		
		memset(buffer, '\0', 16 * 1024);
		int length = resp.pCmd->header_length() + resp.pCmd->body_length();	
		ret = resp.pCmd->encode((byte*)buffer, length);

		resp.releaseCmd();
	
		if(!ret)
		{
			LOG4CPLUS_ERROR(CLogger::logger, "command encode failed for " << name);
			continue;
		}
		
		pSession->write2Send(string(buffer, length));
		int iret = pSession->sendBuffer();
		uint64_t data = U64(resp.seqno, pSession->getFd());
		if(SOCKET_EAGAIN == iret)	//socket»º³åÇøдÂú
		{	
			_epoll_svr_ptr->notify(pSession->getFd(), data, EVENT_WRITE);
		}
		else if(SOCKET_ERR == iret) //socket ³ö´í
		{
			_epoll_svr_ptr->notify(pSession->getFd(), data, EVENT_ERROR);
			_sess_mgr_prt->freeSession(pSession);
			_client_mgr_prt->freeClient(uid, resp.seqno);
		}
		
		LOG4CPLUS_INFO(CDebugLogger::logger, "TimeTace: request[" << resp.idx << "] to response["
				<< name << "] spend time " << current_time_usec() - resp.timestamp);
		Index::free(resp.idx);
	}
}
예제 #3
0
/**
* brief:
*/
void CmdWorker::doIt()
{
	LOG4CPLUS_DEBUG(FLogger, "command worker start work!");

	while(!_terminate)
	{
		CmdTask task;
		bool bret = _task_queue.pop(task, 60*1000);
		if(!bret)
		{
			LOG4CPLUS_DEBUG(FLogger, "task queue is empty! continue wait...");
			continue;
		}

		LOG4CPLUS_INFO(FLogger, "TimeTrace:[" << task.pCmd->get_cmd_name() 
				<< "] out queue spend time " << current_time_usec()- task.timestamp);

		string name = task.pCmd->get_cmd_name();
		ICmdHandlerPtr pHandler = CmdRegistor::getCommand(name);
		if(!pHandler)
		{
			LOG4CPLUS_WARN(FLogger, "couldn't find handler for command["
				<< name << "]");
			
			continue;
		}

		LOG4CPLUS_DEBUG(FLogger, "find a command handler to process command["
				<< name << "]");
		
		pHandler->handle(task);

		LOG4CPLUS_INFO(FLogger, _id << "TimeTrace:[" << task.pCmd->get_cmd_name() 
				<< "] handle spend time " << current_time_usec() - task.timestamp);
		
	}
}
예제 #4
0
파일: schedules.hpp 프로젝트: dlovell/loom
 bool test () const
 {
     return current_time_usec() >= stop_usec_;
 }
예제 #5
0
파일: schedules.hpp 프로젝트: dlovell/loom
 CheckpointingSchedule (const protobuf::Config::Schedule & config) :
     stop_usec_(
         current_time_usec() +
         static_cast<usec_t>(config.checkpoint_period_sec() * 1e6))
 {
 }