コード例 #1
0
/*This function represent each client connection handling from server's point of view */
void ISocketCommunication::handleClientRequest()
{
  try
  {
    
    if( threadStart(pthread_namespace::eDETACH) == -1) {      
      throw("Thread creation failed");
      return;
    }
  
    if( threadStart(pthread_namespace::eDETACH) == -1) {      
      throw("Thread creation failed");
      return;
    }
  
    m_bThreadCreated  = true;
    
    Socket_ReceiveInboundPackets();
  }
  catch(abi::__forced_unwind&)
  {
    throw;
  }
  catch(...)
  {
    
    m_pChatEvtCmd->executeChatEvtCmd(chatevtcmd_namespace::eChildRemoved, nullptr, getpid() );      
    m_pChatEvtCmd->executeChatEvtCmd(chatevtcmd_namespace::eFatalError, nullptr, errno);
    
  }
  
}
コード例 #2
0
/*chatServer constructor */
chatServer::chatServer(std::shared_ptr<cCmdLineParser> pCmdLineParser):cChatApp(pCmdLineParser) 
{
  errno = 0; /* clear error no */
  
  while(1)
  {
    if(P_setThreadSupportNeeded(2)  ==  -1) {     
      break;
    }
        
    pMsgQ_thrd1_S =   std::unique_ptr<cMsgQueue>(new cMsgQueue(mqmsg_namespace::SEND_MODE | mqmsg_namespace::CREATOR_MODE) ); 
    pMsgQ_thrd1_R =   std::unique_ptr<cMsgQueue>(new cMsgQueue(mqmsg_namespace::RECV_MODE) );    
    if( pMsgQ_thrd1_S->mq_Open("/m_Sock_server1") ==  -1) {
      break;
    }    
    if( pMsgQ_thrd1_R->mq_Open("/m_Sock_server1") ==  -1) {      
      break;
    }
        
    pMsgQ_thrd2_S =   std::unique_ptr<cMsgQueue>(new cMsgQueue(mqmsg_namespace::SEND_MODE | mqmsg_namespace::CREATOR_MODE) ); 
    pMsgQ_thrd2_R =   std::unique_ptr<cMsgQueue>(new cMsgQueue(mqmsg_namespace::RECV_MODE) );
    if( pMsgQ_thrd2_S->mq_Open("/m_Sock_server2")  ==  -1)  {      
      break;
    }  
    if( pMsgQ_thrd2_R->mq_Open("/m_Sock_server2") ==  -1) {      
      break;
    }
       
    /* Use semaphore for condition wait/post scenario */  
    m_pSemaphore =   std::unique_ptr<cSemaphore>(new cSemaphore(semaphore_namespace::eCONDITION));
      
    /* This thread does the a)server socket create b) wait for client connection c) messgage exchange with different clients */
    if( threadStart(pthread_namespace::eDETACH)  ==  -1) {/* thread 1 --  */      
      break;
    }
    
    /* This thread does the a)print client stats b) quit  */
    if(threadStart(pthread_namespace::eDETACH) ==  -1) { /* threas 2 -- */      
      break;
    }
    
    break; /* It reached here means no error happend, hence exit while loop */
  }
  
  if(errno)
    throw(strerror(errno));  
   
}
コード例 #3
0
ファイル: ClusterMgr.cpp プロジェクト: leafji/MYSQL_5.7
void
ArbitMgr::threadMain()
{
    ArbitSignal aSignal;
    aSignal = theInputBuffer;
    threadStart(aSignal);
    bool stop = false;
    while (! stop) {
        NdbMutex_Lock(theInputMutex);
        while (! theInputFull) {
            NdbCondition_WaitTimeout(theInputCond, theInputMutex, theInputTimeout);
            threadTimeout();
        }
        aSignal = theInputBuffer;
        theInputFull = false;
        NdbCondition_Signal(theInputCond);
        NdbMutex_Unlock(theInputMutex);
        switch (aSignal.gsn) {
        case GSN_ARBIT_CHOOSEREQ:
            threadChoose(aSignal);
            break;
        case GSN_ARBIT_STOPORD:
            stop = true;
            break;
        }
    }
    threadStop(aSignal);
}
コード例 #4
0
ファイル: serwer.c プロジェクト: Wookesh/SO2
void *clientThread(void *data)
{
	threadStart();
	pthread_t pthread_self();
	pid_t clientPid = *(pid_t *)data, secondClientPid = 0;
	int k = 0, n = 0, m = 0;
	long msgType = clientPid, secondMsgType = 0;
	getRequest(msgType, &k, &n);
	if (getPartner(clientPid, &secondClientPid, k, n, &m) == 1)
		sendErrorInfo(msgType);
	if (secondClientPid != clientPid) {
		secondMsgType = secondClientPid;
		if (getResources(clientPid, secondClientPid, k, n, m) == 0) {
			sendResources(msgType, secondClientPid);
			sendResources(secondMsgType, clientPid);
			getResourcesBack(msgType, secondMsgType, k, n + m);
		} else {
			sendErrorInfo(msgType);
			sendErrorInfo(secondMsgType);
		}
	}
	free(data);
	threadEnd();
	return 0;
}
コード例 #5
0
ファイル: worker_pool.c プロジェクト: zhangjinde/z
int workerPoolStart() {
	assert(M != NULL);
	M->running = 1;
	int i;
	for (i=0; i < M->threadNum; i++) {
		threadStart(M->threads[i]);
	}
	return 0;
}
コード例 #6
0
ファイル: threading.cpp プロジェクト: stxent/yaf
//------------------------------------------------------------------------------
void WorkerThread::start()
{
  const result res = threadStart(&thread);

  if (res != E_OK)
  {
    owner.owner.log("swarm: thread start error");
    exit(EXIT_FAILURE);
  }
}
コード例 #7
0
t_ilm_bool SystemdHealthMonitor::start()
{
    LOG_INFO("SystemdHealthMonitor", "starting");
    t_ilm_bool result = ILM_TRUE;
    if (watchdogEnabled())
    {
        result &= threadCreate();
        result &= threadInit();
        result &= threadStart();
    }
    reportStartupComplete();
    return result;
}
コード例 #8
0
TriggerRoot::TriggerRoot() {
	const char* routine = "TriggerRoot::TriggerRoot";
	
	++(TriggerRoot::instanceCount);
    if (TriggerRoot::instanceCount == 1) {
        try {
        	Ctrig = new pqxx::connection( DataAccess::getConnectionString() );
        }
        catch (const std::exception &e) {
        	L_ERROR(LOG_DB,e.what());
        	throw -1;
        }
        enabled = true;
		threadStart();
    }
}
コード例 #9
0
void jsStartMainThread()
{
	threadStart(g_threads + 0);
}
コード例 #10
0
ファイル: eventloop.c プロジェクト: zhangjinde/z
void eventloopStart() {
	threadStart(M->thread);
}
コード例 #11
0
ファイル: threadtest.cpp プロジェクト: pfedick/pplib
void TestThread::start()
{
	threadStart();
}
コード例 #12
0
ファイル: Download.cpp プロジェクト: yirenzhi/jake
void Download::start()
{
	if(!Screen::getResDownTemplate(saveName)){
		threadStart();
	}
}
コード例 #13
0
ファイル: thread.cpp プロジェクト: 87maxi/oom
void Thread::loop()
{
	// Changed by Tim. p3.3.17

	if (!debugMode)
	{
		if (mlockall(MCL_CURRENT | MCL_FUTURE))
			perror("WARNING: Cannot lock memory:");
	}

	/*
		  pthread_attr_t* attributes = 0;
		  attributes = (pthread_attr_t*) malloc(sizeof(pthread_attr_t));
		  pthread_attr_init(attributes);

		  if (realTimeScheduling && realTimePriority > 0) {

				doSetuid();
	//             if (pthread_attr_setschedpolicy(attributes, SCHED_FIFO)) {
	//                   printf("cannot set FIFO scheduling class for RT thread\n");
	//                   }
	//             if (pthread_attr_setscope (attributes, PTHREAD_SCOPE_SYSTEM)) {
	//                   printf("Cannot set scheduling scope for RT thread\n");
	//                   }
	//             struct sched_param rt_param;
	//             memset(&rt_param, 0, sizeof(rt_param));
	//             rt_param.sched_priority = realTimePriority;
	//             if (pthread_attr_setschedparam (attributes, &rt_param)) {
	//                   printf("Cannot set scheduling priority %d for RT thread (%s)\n",
	//                      realTimePriority, strerror(errno));
	//                   }

			   // do the SCHED_FIFO stuff _after_ thread creation:
			   struct sched_param *param = new struct sched_param;
			   param->sched_priority = realTimePriority;
			   int error = pthread_setschedparam(pthread_self(), SCHED_FIFO, param);
				if (error != 0)
				  perror( "error set_schedparam 2:");

	//          if (!debugMode) {
	//                if (mlockall(MCL_CURRENT|MCL_FUTURE))
	//                      perror("WARNING: Cannot lock memory:");
	//                }

				undoSetuid();
				}

	 */


	/*
	#define BIG_ENOUGH_STACK (1024*1024*1)
		  char buf[BIG_ENOUGH_STACK];
		  for (int i = 0; i < BIG_ENOUGH_STACK; i++)
				buf[i] = i;
	#undef BIG_ENOUGH_STACK
	 */

#ifdef __APPLE__
#define BIG_ENOUGH_STACK (1024*256*1)
#else
#define BIG_ENOUGH_STACK (1024*1024*1)
#endif
	char buf[BIG_ENOUGH_STACK];
	for (int i = 0; i < BIG_ENOUGH_STACK; i++)
		buf[i] = i;
#undef BIG_ENOUGH_STACK

	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0);
	pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, 0);

	int policy = 0;
	if ((policy = sched_getscheduler(0)) < 0)
	{
		printf("Thread: Cannot get current client scheduler: %s\n", strerror(errno));
	}

	/*
	if (debugMsg)
		  printf("Thread <%s> set to %s priority %d\n",
			 _name, policy == SCHED_FIFO ? "SCHED_FIFO" : "SCHED_OTHER",
			  realTimePriority);
	 */
	if (debugMsg)
		printf("Thread <%s, id %p> has %s priority %d\n",
			_name, (void *) pthread_self(), policy == SCHED_FIFO ? "SCHED_FIFO" : "SCHED_OTHER",
			_realTimePriority);


	//      pthread_mutex_lock(&lock);
	_running = true;
	//      pthread_cond_signal(&ready);
	//      pthread_mutex_unlock(&lock);

	threadStart(userPtr);

	while (_running)
	{
		if (debugMode) // DEBUG
			_pollWait = 10; // ms
		else
			_pollWait = -1;

		int n = poll(pfd, npfd, _pollWait);
		if (n < 0)
		{
			if (errno == EINTR)
				continue;
			fprintf(stderr, "poll failed: %s\n", strerror(errno));
			exit(-1);
		}
		if (n == 0)
		{ // timeout
			defaultTick();
			continue;
		}

		struct pollfd* p = &pfd[0];
		int i = 0;
		for (iPoll ip = plist.begin(); ip != plist.end(); ++ip, ++p, ++i)
		{
			if (ip->action & p->revents)
			{
				(ip->handler)(ip->param1, ip->param2);
				break;
			}
		}
	}
	threadStop();
}