Example #1
0
void CFlukeSlave::flukeslave(HMODULE hmod)
{
  DBGTRACE("CFlukeSlave::flukeslave\n");
  CSyncClient sync1("IOFlukeApp",GetCurrentThreadId());
  DBGTRACE("sync1.IsExist()==%s\n",sync1.IsExist()?"true":"false");
  if(!sync1.IsExist())
    return;

  char name[MAX_PATH];
  DWORD sname=GetModuleFileName(hmod,name,sizeof(name));
  if(sname==0||(sname==sizeof(name)))
    throw FlukeException("Path Test");
  DBGTRACE("LoadLibrary(%s)\n",name);
  m_library=LoadLibrary(name);

  CSyncServer sync2("IOFlukeDll",GetCurrentThreadId());

  DBGTRACE("sync1.RunClient()\n",hmod);
  sync1.RunClient();

  DBGTRACE("sync2.WaitClient()\n",hmod);
  sync2.WaitClient();

  std::ostringstream str;
  str<<g_flukeslaveready<<GetCurrentThreadId();
  DBGTRACE("m_globalpass: %s\n",str.str().c_str());
  m_globalpass=CreateMutex(0,TRUE,str.str().c_str());

  DBGTRACE("InitInstance(%08x)\n",hmod);
  FlukeInit(hmod);
}
VOID BL_ThreadPoolWorkThread::CancelTaskByType(BL_TASKTYPE nTaskType, DWORD dwCancelSequenceIndex)
{
    CL_BOOL bRunTaskCancelFlg = CL_FALSE;
    // find task in waitlist and canceled
    {
        BL_AutoSync sync(m_cSyncObj);
        BaseList<BL_ThreadPoolTask*>::iterator it;
        for (it = m_cRunTaskList.begin(); it != m_cRunTaskList.end(); ++it) {
            BL_ThreadPoolTask* pcTask = *it;
            if (NULL != pcTask
                && pcTask->GetTaskType() == nTaskType
                && pcTask->GetSequenceIndex() < dwCancelSequenceIndex) {
                pcTask->m_bCanceledFlag = CL_TRUE;
            }
        }
        // check the current run task and set the cancel flag,
        // the task is running currently or will be canceld.
        if (NULL != m_pCurrentRunTask) {
            if (m_pCurrentRunTask->GetTaskType() == nTaskType
                && m_pCurrentRunTask->GetSequenceIndex() < dwCancelSequenceIndex) {
                bRunTaskCancelFlg = CL_TRUE;
                m_pCurrentRunTask->m_bCanceledFlag = CL_TRUE;
            }
        }
    }
    // cancel current runtask
    if (bRunTaskCancelFlg) {
        // for preventing task waitlist operation chock, must lock taskrunning first.
        BL_AutoSync sync1(m_sRunSyncObj);
        BL_AutoSync sync2(m_cSyncObj);
        if (NULL != m_pCurrentRunTask) {
            if (m_pCurrentRunTask->GetTaskType() == nTaskType
                && m_pCurrentRunTask->GetSequenceIndex() < dwCancelSequenceIndex) {
                m_pCurrentRunTask->m_bCanceledFlag = CL_TRUE;
            }
        }
    }
}
Example #3
0
void foreach_attrib(AttributeContainer& attr_cont, std::vector<FunctorAttribThreaded*> funcs)
{
	unsigned int nbth = funcs.size();

	std::vector<unsigned int >* vid = new std::vector<unsigned int>[2*nbth];
	boost::thread** threads = new boost::thread*[nbth];

	for (unsigned int i = 0; i < 2*nbth; ++i)
		vid[i].reserve(SIZE_BUFFER_THREAD);

	// fill each vid buffers with 4096 id
	unsigned int id = attr_cont.begin();
	unsigned int nb = 0;
	unsigned int nbm = nbth*SIZE_BUFFER_THREAD;
	while ((id != attr_cont.end()) && (nb < nbm))
	{
		vid[nb%nbth].push_back(id);
		nb++;
		attr_cont.next(id);
	}


	boost::barrier sync1(nbth+1);
	boost::barrier sync2(nbth+1);
	bool finished=false;
	// lauch threads
	for (unsigned int i = 0; i < nbth; ++i)
		threads[i] = new boost::thread(ThreadFunctionAttrib(funcs[i], vid[i],sync1,sync2, finished,1+i));

	while (id != attr_cont.end())
	{
		for (unsigned int i = nbth; i < 2*nbth; ++i)
			vid[i].clear();

		unsigned int nb = 0;
		while ((id != attr_cont.end()) && (nb < nbm))
		{
			vid[nbth + nb%nbth].push_back(id);
			nb++;
			attr_cont.next(id);
		}

		sync1.wait();
		for (unsigned int i = 0; i < nbth; ++i)
			vid[i].swap(vid[nbth+i]);
		sync2.wait();
	}

	sync1.wait();
	finished = true;
	sync2.wait();

	//wait for all theads to be finished
	for (unsigned int i = 0; i < nbth; ++i)
	{
		threads[i]->join();
		delete threads[i];
	}
	delete[] threads;
	delete[] vid;
}