Example #1
0
bool CDispatcherContext::create_thread_pool()
{        
    try
    {                                    
        // 创建线程池
        // 只有CThread::before_start返回false,create才会返回false
        _thread_pool = new CSendThreadPool;
        _thread_pool->create(_thread_count, this);
        DISPATCHER_LOG_INFO("Sender thread number is %d.\n", _thread_pool->get_thread_count());

        CSendThread** send_thread = _thread_pool->get_thread_array();
        uint16_t thread_count = _thread_pool->get_thread_count();
        for (uint16_t i=0; i<thread_count; ++i)
        {                        
            send_thread[i]->wakeup();
        }

        return true;
    }
    catch (sys::CSyscallException& syscall_ex)
    {
        delete _thread_pool;
        DISPATCHER_LOG_ERROR("Failed to create thread pool: %s.\n", syscall_ex.str().c_str());
    }

    return false;
}
Example #2
0
int main(int argc, const char *argv[], bool bUsePrefix)
{
    std::auto_ptr<MFX_DISP_HANDLE> allocatedHandle;
    MFX_DISP_HANDLE *pHandle;
    mfxIMPL impl = MFX_IMPL_AUTO;
    mfxVersion ver = {0, 0};
    int i;

    if ((2 == argc) &&
        ('?' == argv[1][0]))
    {
        printf("USAGE: %s -[s|h] [-v<version>]\n", argv[0]);
        printf("Where:\n");
        printf("    -s  - use MFX_IMPL_SOFTWARE dispatching type (optional).\n");
        printf("    -h  - use MFX_IMPL_HARDWARE dispatching type (optional).\n");
        printf("    -ha - use MFX_IMPL_HARDWARE_ANY dispatching type (optional).\n");
        printf("    -h2 - use MFX_IMPL_HARDWARE2 dispatching type (optional).\n");
        printf("    -h3 - use MFX_IMPL_HARDWARE2 dispatching type (optional).\n");
        printf("    -h4 - use MFX_IMPL_HARDWARE2 dispatching type (optional).\n");
        printf("    -v - use specified API version (optional).\n");
        printf("         <version> can be required in X.Y format\n");
        return -1;
    }

    // parse parameters
    for (i = 1; i < argc; i += 1)
    {
        if ('-' == argv[i][0])
        {
            switch (argv[i][1])
            {
            // use MFX_IMPL_SOFTWARE dispatching type
            case 's':
            case 'S':
                impl = MFX_IMPL_SOFTWARE;
                break;

            // use MFX_IMPL_HARDWARE dispatching type
            case 'h':
            case 'H':
            {
                switch (argv[i][2])
                {
                    case 'a':impl = MFX_IMPL_HARDWARE_ANY;break;
                    case '2':impl = MFX_IMPL_HARDWARE2;break;
                    case '3':impl = MFX_IMPL_HARDWARE3;break;
                    case '4':impl = MFX_IMPL_HARDWARE4;break;
                    default :impl = MFX_IMPL_HARDWARE;break;
                }

                break;
            }
                
            // read specified API version
            case 'v':
            case 'V':
            {
                int x = 2;

                // read major version
                while (('0' <= argv[i][x]) &&
                       ('9' >= argv[i][x]))
                {
                    ver.Major = ver.Major * 10 + (argv[i][x] - '0');
                    x += 1;
                }
                // skip delimiter
                if (argv[i][x])
                {
                    x += 1;
                }
                // read minor version
                while (('0' <= argv[i][x]) &&
                       ('9' >= argv[i][x]))
                {
                    ver.Minor = ver.Minor * 10 + (argv[i][x] - '0');
                    x += 1;
                }
            }
            break;

            default:
                DISPATCHER_LOG_ERROR(("unknown parameter %s. Specify ? flag for help.\n", argv[i]));
                break;
            }
        }
        else
        {
            DISPATCHER_LOG_ERROR(("unknown parameter %s. Specify ? flag for help.\n", argv[i]));
        }
    }

    DISPATCHER_LOG_INFO(("current platform: %s\n", cPlatform));
    DISPATCHER_LOG_INFO(("implementation: %s\n", DispatcherLog_GetMFXImplString(impl).c_str()));

    sdk_library library;

    if (bUsePrefix)
    {
        if (MFX_ERR_NONE == DISPATCHER_EXPOSED_PREFIX(MFXInit)(impl, ver.Version?&ver:NULL, (mfxSession*)&pHandle))
        {
            DISPATCHER_EXPOSED_PREFIX(MFXClose)((mfxSession)pHandle);
        }
    }
    else
    {
        if (MFX_ERR_NONE == MFXInit(impl, ver.Version?&ver:NULL, (mfxSession*)&pHandle))
        {
            MFXClose((mfxSession)pHandle);
        }
    }

    DISPATCHER_LOG_INFO(("DISPRESULT: platform=%-5s impl=%-21s ver=%d.%d : %s\n"
        , cPlatform
        , DispatcherLog_GetMFXImplString(impl).c_str()
        , ver.Major , ver.Minor 
        , library.GetPath().empty()? "NOT FOUND" : library.GetPath().c_str()));

    return 0;

} // int main(int argc, const char *argv[])