Exemplo n.º 1
0
int
main ()
{
    int arg,cres,fres;

    printf ("Welcome to GNU libtool mixed C/Fortran demo!\n");

    arg = 2;

    cres = csub (arg);

    printf ("The C subroutine returned, claiming that 2*%d = %d\n",arg,cres);

    if (cres == 2*arg)
        printf ("The C subroutine is ok!\n");

    printf ("\nCalling the C wrapper routine...\n");
    fres = fwrapper (arg);

    printf ("The C wrapper to the fortran subroutine returned,\n"
            "claiming that 2*%d = %d\n",arg,fres);

    if (fres == 2*arg)
        printf ("The Fortran subroutine is ok!\n");

    return 0;
}
Exemplo n.º 2
0
string DbProxy::getLastTime(const map<string,string>& mSqlPart)
{
    string sUid    = mSqlPart.find("uid")->second;

    string min = "99999999999"; // 求最小的,初始使用很大的数据
    //TLOGDEBUG("mSqlPart"<< mSqlPart.find("dataid")->second <<endl);
    try
    {
        typedef TC_Functor<void, TL::TLMaker<const string &, int, const string &, const TC_DBConf &, string &, QueryParam &>::Result> CheckTimeFun;
        typedef CheckTimeFun::wrapper_type CheckTimeFunWrapper;

        vector<TC_DBConf> vDbInfo = g_app.getAllActiveDbInfo();

        int iThreads = vDbInfo.size();

        if(iThreads > 0)
        {
            vector<string> res(iThreads);

            //vector<string> vsTbNamePre(iThreads);

            CheckTimeFun qeryCMD(selectLastMinTime);

            _queryParam._run_times = iThreads;

            int64_t tStart    = TC_TimeProvider::getInstance()->getNowMs();

            for (int i=0; i< iThreads; i++)
            {
                //vsTbNamePre[i] = vDbInfo[i]._database + "_";
                //vsTbNamePre[i] = vDbInfo[i]._database;

            //    TLOGDEBUG("mSqlPart"<< mSqlPart["dataid"] <<endl);
            //    CheckTimeFunWrapper fwrapper(qeryCMD, sUid, i, mSqlPart["dataid"], vDbInfo[i], res[i], _queryParam);
                CheckTimeFunWrapper fwrapper(qeryCMD, sUid, i,  mSqlPart.find("dataid")->second, vDbInfo[i], res[i], _queryParam);

                g_app.getThreadPoolTimeCheck().exec(fwrapper);
            }

            TLOGDEBUG("DbProxy::getLastTime sUid:" << sUid << "wait for getLastTime done." << endl);
            
            bool rc = true;
            int ifail = 0;
            while(_queryParam._atomic.get() != _queryParam._run_times)
            {
                {
                    TC_ThreadLock::Lock lock(_queryParam._monitor);
                    rc = _queryParam._monitor.timedWait(300);
                }

                ++ifail;

                if(!rc)
                {
                    if(ifail >= 10)
                    {
                        break;
                    }
                }
            }

            if(ifail >= 10)
            {
                TLOGDEBUG("DbProxy::getLastTime sUid:" << sUid << "wait for getLastTime timeout." << endl);
                while(_queryParam._atomic.get() != _queryParam._run_times)
                {
                    {
                        TC_ThreadLock::Lock lock(_queryParam._monitor);
                        _queryParam._monitor.timedWait(1000);
                    }
                }
            }

            if(_queryParam._atomic.get() == _queryParam._run_times)
                rc = true;
            /*bool rc = false;
            {
                TC_ThreadLock::Lock lock(_queryParam._monitor);
                rc = _queryParam._monitor.timedWait(3000);
            }*/

            int64_t tEnd = TC_TimeProvider::getInstance()->getNowMs();


            if(rc)
            {
                TLOGDEBUG("DbProxy::getLastTime sUid:" << sUid << "getLastTime all done|return:" << _queryParam._run_result <<"|timecost(ms):" << (tEnd-tStart) << endl);

                for(int i = 0; i < iThreads; ++i)
                {
                    if(res[i] < min)
                    {
                        min = res[i];
                    }
                }
            }
            else
            {
                min = "";
                TLOGDEBUG("DbProxy::getLastTime sUid:" << sUid << "getLastTime timeout." << endl);
            }
        }
        else
        {
            min = "";
        }

        TLOGDEBUG("DbProxy::getLastTime sUid:" << sUid << "final lasttime:" << min << endl);
    }
    catch (exception &ex)
    {
        TLOGERROR("DbProxy::getLastTime exception:" << ex.what() << endl);
        min = "";    
    }

    _queryParam._run_times = 0;
    _queryParam._run_result = 0;
    _queryParam._atomic = 0;

    return min;
}
Exemplo n.º 3
0
/**
 * 通过线程池进行并发查询
 */
void DbProxy::queryData(map<string, string> &mSqlPart, string &sResult, bool bDbCountFlag)
{
    typedef TC_Functor<void, TL::TLMaker<int, const TC_DBConf &, map<string,string>&, map<string,vector<double> >&, string&, QueryParam &,string&>::Result> QueryFun;
    typedef QueryFun::wrapper_type QueryFunWrapper;

    try
    {
        string sUid = mSqlPart.find("uid")->second;

        vector<TC_DBConf> vActive;

        if(bDbCountFlag)
        {
            vActive = g_app.getActiveDbInfo();
        }
        else
        {
            //vActive = g_app.getActiveDbInfo();
        }

        int iThreads = vActive.size();

        //int iThreads = bDbCountFlag ? g_app.getDbNumber() : g_app.getDbNumber();
        if(iThreads > 0)
        {
            vector<string> vPolicy(iThreads);

            vector<string> res(iThreads);

            vector<map<string, vector<double> > >  vDataList(iThreads);

            QueryFun qeryCMD(query);

            _queryParam._run_times = iThreads;

            //TLOGDEBUG("DbProxy::queryData sUid:" << sUid << "all thread query data begin." << endl);

            int64_t tStart    = TC_TimeProvider::getInstance()->getNowMs();

            for(int i=0; i < iThreads; i++)
            {
                QueryFunWrapper fwrapper(qeryCMD, i, vActive[i], mSqlPart, vDataList[i], res[i], _queryParam,vPolicy[i]);

                if(bDbCountFlag)
                {
                    g_app.getThreadPoolDb().exec(fwrapper);
                }
                else
                {
                    //g_app.getThreadPoolDb().exec(fwrapper);                
                }
            }

            //等待线程结束
            TLOGDEBUG("DbProxy::queryData sUid:" << sUid << "wait for all thread query data done." << endl);

            bool rc = true;
            int ifail = 0;
            while(_queryParam._atomic.get() != _queryParam._run_times)
            {
                {
                    TC_ThreadLock::Lock lock(_queryParam._monitor);
                    rc = _queryParam._monitor.timedWait(6000);
                }

                ++ifail;

                if(!rc)
                {
                    if(ifail >= 10)
                    {
                        break;
                    }
                }
            }

            if(ifail >= 10)
            {
                TLOGDEBUG("DbProxy::queryData sUid:" << sUid << "wait for all thread query data timeout." << endl);
                while(_queryParam._atomic.get() != _queryParam._run_times)
                {
                    {
                        TC_ThreadLock::Lock lock(_queryParam._monitor);
                        _queryParam._monitor.timedWait(1000);
                    }
                }
            }

            if(_queryParam._atomic.get() == _queryParam._run_times)
                rc = true;
            /*bool rc = false;
            {
                TC_ThreadLock::Lock lock(_queryParam._monitor);
                rc = _queryParam._monitor.timedWait(60000);
            }*/
            
            int64_t tEnd = TC_TimeProvider::getInstance()->getNowMs();

            if(rc)
            {
                _queryParam._run_times = 0;
                _queryParam._run_result = 0;
                _queryParam._atomic = 0;

                TLOGDEBUG("DbProxy::queryData sUid:" << sUid << "all thread done return:" << _queryParam._run_result <<"|timecost(ms):" << (tEnd - tStart) << endl);

                // 返回ret code
                string sHead;

                string sLasttime = getLastTime(mSqlPart);

                if(createRespHead(res, sLasttime, sHead, bDbCountFlag) != 0)
                {
                    _queryParam._run_times = 0;
                    _queryParam._run_result = 0;
                    _queryParam._atomic = 0;

                    sResult = sHead;
                    TLOGERROR("DbProxy::queryData query error:" << sHead << endl);
                    return;
                }

                createRespData(sUid, mSqlPart, vDataList, sHead, sResult,vPolicy[vPolicy.size()-1]);
            }
            else
            {
                sResult ="Ret:-1\nquery timeout\n";

                TLOGDEBUG("DbProxy::queryData sUid:" << sUid << "Ret:-1|query timeout." << endl);
            }
        }
        else
        {
            sResult ="Ret:-1\nno active db\n";
        }
    }
    catch (exception &ex)
    {
        TLOGERROR("DbProxy::queryData exception:" << ex.what() << endl);
        sResult ="Ret:-1\n" + string(ex.what()) + "\n";        
    }

    _queryParam._run_times = 0;
    _queryParam._run_result = 0;
    _queryParam._atomic = 0;
}