Exemplo n.º 1
0
//
// Clean up the library and exit
//
//
//
extern "C" BC_ERROR CMP_ShutdownBCLibrary(void)
{
    if(!g_LibraryInitialized)
    {
        return BC_ERROR_LIBRARY_NOT_INITIALIZED;
    }
    Quant_DeInit();
    g_LibraryInitialized = FALSE;

    return BC_ERROR_NONE;
}
Exemplo n.º 2
0
CCodec_BC6H::~CCodec_BC6H()
{
    if (m_LibraryInitialized)
    {

        if (m_Use_MultiThreading)
        {
            // Tell all the live threads that they can exit when they have finished any current work
            for(int i=0; i < m_LiveThreads; i++)
            {
                // If a thread is in the running state then we need to wait for it to finish
                // any queued work from the producer before we can tell it to exit.
                //
                // If we don't wait then there is a race condition here where we have
                // told the thread to run but it hasn't yet been scheduled - if we set
                // the exit flag before it runs then its block will not be processed.
#pragma warning(push)
#pragma warning(disable:4127) //warning C4127: conditional expression is constant
                while(1)
                {
                    if (g_BC6EncodeParameterStorage == NULL) break;
                    if(g_BC6EncodeParameterStorage[i].run != TRUE)
                    {
                        break;
                    }
                }
#pragma warning(pop)
                // Signal to the thread that it can exit
                g_BC6EncodeParameterStorage[i].exit = TRUE;
            }

            // Now wait for all threads to have exited
            if(m_LiveThreads > 0)
            {
                WaitForMultipleObjects(m_LiveThreads,
                                       m_EncodingThreadHandle,
                                       true,
                                       INFINITE);
            }

        } // MultiThreading

        for(int i=0; i < m_LiveThreads; i++)
        {
            if(m_EncodingThreadHandle[i])
            {
                CloseHandle(m_EncodingThreadHandle[i]);
            }
            m_EncodingThreadHandle[i] = 0;
        }

        delete[] m_EncodingThreadHandle;
        m_EncodingThreadHandle = NULL;

        delete[] g_BC6EncodeParameterStorage;
        g_BC6EncodeParameterStorage = NULL;

        
        for(int i=0; i < m_NumEncodingThreads; i++)
        {
            if (m_encoder[i])
            {
                delete m_encoder[i];
                m_encoder[i] = NULL;
            }
        }

        if (m_decoder)
        {
            delete m_decoder;
            m_decoder = NULL;
        }

        Quant_DeInit();
        m_LibraryInitialized = false;
    }
}