当前位置: 首页>>代码示例>>C++>>正文


C++ SymbolString::GetVal方法代码示例

本文整理汇总了C++中SymbolString::GetVal方法的典型用法代码示例。如果您正苦于以下问题:C++ SymbolString::GetVal方法的具体用法?C++ SymbolString::GetVal怎么用?C++ SymbolString::GetVal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SymbolString的用法示例。


在下文中一共展示了SymbolString::GetVal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: fkt_nthread

// nthread(iNumThreads, strFunc, vecArgs, ...)
static Symbol* fkt_nthread(const std::vector<Symbol*>& vecSyms,
	ParseInfo& info, RuntimeInfo &runinfo, SymbolTable* pSymTab)
{
	if(vecSyms.size()<3)
	{
		std::ostringstream ostrErr;
		ostrErr << linenr(runinfo) 
			<< "nthread needs at least 3 arguments: N, func, arg." 
			<< std::endl;
		throw tl::Err(ostrErr.str(),0);
	}

	Symbol* _pSymN = vecSyms[0];
	if(_pSymN->GetType() != SYMBOL_INT)
	{
		std::ostringstream ostrErr;
		ostrErr << linenr(runinfo) << "Number of threads has to be integer." << std::endl;
		throw tl::Err(ostrErr.str(),0);
	}

	SymbolInt *pSymN = (SymbolInt*)_pSymN;
	t_int iNumThreads = pSymN->GetVal();



	Symbol* _pSymIdent = vecSyms[1];
	if(_pSymIdent->GetType() != SYMBOL_STRING)
	{
		std::ostringstream ostrErr;
		ostrErr << linenr(runinfo) << "Thread proc identifier needs to be a string." << std::endl;
		throw tl::Err(ostrErr.str(), 0);
	}

	SymbolString *pSymIdent = (SymbolString*)_pSymIdent;
	const t_string& strIdent = pSymIdent->GetVal();



	Symbol* _pSymArr = vecSyms[2];
	if(_pSymArr->GetType() != SYMBOL_ARRAY)
	{
		std::ostringstream ostrErr;
		ostrErr << linenr(runinfo) << "Thread arg has to be an array." << std::endl;
		throw tl::Err(ostrErr.str(), 0);
	}

	SymbolArray *pSymArr = (SymbolArray*)_pSymArr;
	const std::vector<Symbol*>& vecArr = pSymArr->GetArr();



	NodeFunction* pFunc = info.GetFunction(strIdent);
	if(pFunc == 0)
	{
		std::ostringstream ostrErr;
		ostrErr << linenr(runinfo) << "Thread proc \"" << strIdent 
			<< "\" not defined." << std::endl;
		throw tl::Err(ostrErr.str(), 0);
	}





	if(iNumThreads > int(vecArr.size()))
	{
		iNumThreads = vecArr.size();
		tl::log_warn(linenr(runinfo), "More threads requested in nthread than necessary, ",
					"reducing to array size (", iNumThreads, ").");
	}


	std::vector<SymbolArray*> vecSymArrays;
	vecSymArrays.resize(iNumThreads);

	t_int iCurTh = 0;
	for(Symbol* pThisSym : vecArr)
	{
		if(!vecSymArrays[iCurTh])
			vecSymArrays[iCurTh] = new SymbolArray();

		vecSymArrays[iCurTh]->GetArr().push_back(pThisSym->clone());
		vecSymArrays[iCurTh]->UpdateLastNIndices(1);

		++iCurTh;
		if(iCurTh == iNumThreads)
			iCurTh = 0;
	}



	std::vector<std::thread*> vecThreads;
	vecThreads.reserve(iNumThreads);

	for(iCurTh=0; iCurTh<iNumThreads; ++iCurTh)
	{
		std::vector<Symbol*>* vecThreadSyms = new std::vector<Symbol*>;
		vecThreadSyms->reserve(vecSyms.size()-3+1);

//.........这里部分代码省略.........
开发者ID:t-weber,项目名称:tlibs,代码行数:101,代码来源:calls_thread.cpp

示例2: fkt_thread_task

static Symbol* fkt_thread_task(const std::vector<Symbol*>& vecSyms,
	ParseInfo& info, RuntimeInfo &runinfo, 
	SymbolTable* pSymTab, bool bTask=0)
{
	if(vecSyms.size()<1)
	{
		std::ostringstream ostrErr;
		ostrErr << linenr(runinfo) << "Need thread proc identifier." << std::endl;
		throw tl::Err(ostrErr.str(), 0);
	}

	Symbol* _pSymIdent = vecSyms[0];
	if(_pSymIdent->GetType() != SYMBOL_STRING)
	{
		std::ostringstream ostrErr;
		ostrErr << linenr(runinfo) << "Thread proc identifier needs to be a string." << std::endl;
		throw tl::Err(ostrErr.str(), 0);
	}

	SymbolString *pSymIdent = (SymbolString*)_pSymIdent;
	const t_string& strIdent = pSymIdent->GetVal();


	NodeFunction* pFunc = info.GetFunction(strIdent);
	if(pFunc == 0)
	{
		std::ostringstream ostrErr;
		ostrErr << linenr(runinfo) << "Thread proc \"" << strIdent << "\" not defined." << std::endl;
		throw tl::Err(ostrErr.str(), 0);
	}

	std::vector<Symbol*>* vecThreadSymsClone = clone_symbols(&vecSyms, 1);

	t_int iHandle = -1;
	if(bTask)
	{
		bool bIsThread = 1;
		std::launch policy = std::launch::async /*| std::launch::deferred*/;
		unsigned int iNumThreads = info.phandles->CountAllThreads();
		//log_debug("Number of threads running: ", iNumThreads);

		// start deferred
		if(iNumThreads >= std::thread::hardware_concurrency())
		{
			bIsThread = 0;
			// let system decide
			policy |= std::launch::deferred;
			//log_debug("starting (probably) deferred");
		}
		//else log_debug("starting as thread");

		std::future<Symbol*> *pFuture = new std::future<Symbol*>(
			std::async(policy, ::task_proc, pFunc, &info, vecThreadSymsClone));
		iHandle = info.phandles->AddHandle(new HandleTask(pFuture, bIsThread));
	}
	else
	{
		std::thread* pThread = new std::thread(::thread_proc, pFunc, &info, vecThreadSymsClone);
		iHandle = info.phandles->AddHandle(new HandleThread(pThread));
	}

	return new SymbolInt(iHandle);
}
开发者ID:t-weber,项目名称:tlibs,代码行数:63,代码来源:calls_thread.cpp


注:本文中的SymbolString::GetVal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。