void CMultiThreadReadTest::Run()
{
	m_running = true;
	if (m_filelist.size() > (unsigned)m_filecount)
	{
		m_filelist.resize((unsigned)m_filecount);
	}
	int count = (int)m_filelist.size();
	for (int i = 0; i < count; i++)
	{
		std::thread *t = new std::thread(std::bind(&CMultiThreadReadTest::ThreadRun,
			this, m_filelist[i]));
		m_threadlist[i] = t;
	}
	
	while (m_thread_count < count)
	{
		sched_yield();
	}
	m_bench.Start();

	NotifyStart();
	WaitStop();

	/* cleanup */
	for (unsigned i = 0; i < count; i++)
	{
		m_threadlist[i]->join();
		delete m_threadlist[i];
	}
	m_threadlist.clear();
}
Example #2
0
void 
CreamConnection(creamConnection_t *connection)
{ 
/*
startnotify 	controls the normal operation in PollDB
startnotifyjob 	is used to send notification of jobs contained in joblist_string 
firstnotify 	controls if NTFDATE/END has to be sent (together with sentendonce)
sentendonce 	controls if NTFDATE/END has to be sent (is used to permit STARTNOTIFYJOBLIST to be used during
            	normal notifier operation without sending NTFDATE/END). It is reset to TRUE only by CREAMFILTER command
            	otherwise it remains FALSE after the first notification (finished with NTFDATE/END).
creamisconn 	starts all the normal usage: without it no notifications are sent to cream

So the initial commands should be:
CREAMFILTER
PARSERVERSION

STARTNOTIFY 
or 
STARTNOTIFYJOBLIST
STARTNOTIFYJOBEND

during the normal usage to have info about a list of job:
STARTNOTIFYJOBLIST
STARTNOTIFYJOBEND

*/

	char *buffer;
	int  conn_c = connection->socket_fd;

	if((buffer=calloc(LISTBUFFER,1)) == 0){
		sysfatal("can't malloc buffer in CreamConnection: %r");
	}

	while (Readline(conn_c, buffer, LISTBUFFER-1) > 0) {
		if(strlen(buffer) > 0)
		{
			do_log(debuglogfile, debug, 1, "Received for Cream:%s\n", buffer);
			if (strstr(buffer,"STARTNOTIFY/") != NULL) {
				NotifyStart(buffer, &(connection->lastnotiftime));
				connection->startnotify=TRUE;
				connection->firstnotify=TRUE;
			} else if (strstr(buffer,"STARTNOTIFYJOBLIST/") != NULL) {
				GetJobList(buffer, &(connection->joblist_string));
				connection->startnotifyjob = TRUE;
				connection->startnotify = FALSE;
			} else if (strstr(buffer,"STARTNETWORKSYNC/") != NULL) {
				GetJobList(buffer, &(connection->joblist_string));
				connection->startnotifyjob = TRUE;
				connection->startnotify = FALSE;
			} else if (strstr(buffer,"STARTNOTIFYJOBEND/") != NULL) {
				connection->firstnotify=TRUE;
				connection->lastnotiftime = time(NULL);
			} else if (strstr(buffer,"CREAMFILTER/") != NULL) {
				GetFilter(buffer, connection->socket_fd, &(connection->creamfilter));
				connection->creamisconn=TRUE;
				connection->sentendonce=TRUE;
			} else if (strstr(buffer,"PARSERVERSION/") != NULL) {
				GetVersion(connection->socket_fd);
			}
		}
	}
	connection->creamisconn=FALSE;
	close(conn_c);
	free(buffer);
	connection->socket_fd = 0;
	if (connection->creamfilter) 
	{
		free(connection->creamfilter);
		connection->creamfilter = NULL;
	}
}