Exemple #1
0
            internal void ThreadFunc()
            {
                for (;;)
                {
                    CMtThread next = GET_NEXT_THREAD();

                    bool stop;
                    SRes res = MtThread_Process(out stop);
                    if (res != SZ_OK)
                    {
                        mMtCoder.MtCoder_SetError(res);
                        mMtCoder.mMtProgress.MtProgress_SetError(res);

                        Trace.MatchObjectWait(this, "ThreadFunc");
                        next.mStopReading = true;
                        next.mStopWriting = true;
                        Trace.MatchObjectWait(this, "ThreadFunc");

                        Event_Set(next.mCanRead);
                        Event_Set(next.mCanWrite);
                        return; // res;
                    }

                    if (stop)
                    {
                        return; // 0;
                    }
                }
            }
Exemple #2
0
            internal CMtCoder() // MtCoder_Construct
            {
                mAlloc = null;

                mThreads = new CMtThread[NUM_MT_CODER_THREADS_MAX];
                for (int i = 0; i < mThreads.Length; i++)
                {
                    mThreads[i] = new CMtThread(i, this);
                }

                CriticalSection_Init(out mCS);
                CriticalSection_Init(out mMtProgress.mCS);
            }
Exemple #3
0
            internal SRes MtCoder_Code()
            {
                int  numThreads = mNumThreads;
                SRes res        = SZ_OK;

                mRes = SZ_OK;

                mMtProgress.MtProgress_Init(mProgress);

                for (uint i = 0; i < numThreads; i++)
                {
                    if ((res = mThreads[i].CMtThread_Prepare()) != SZ_OK)
                    {
                        return(res);
                    }
                }

                for (uint i = 0; i < numThreads; i++)
                {
                    CMtThread   t  = mThreads[i];
                    CLoopThread lt = t.mThread;

                    if (!Thread_WasCreated(lt.mThread))
                    {
                        lt.mFunc = t.ThreadFunc;
                        if (lt.LoopThread_Create() != SZ_OK)
                        {
                            res = SZ_ERROR_THREAD;
                            break;
                        }
                    }
                }

                if (res == SZ_OK)
                {
                    int i;
                    for (i = 0; i < numThreads; i++)
                    {
                        CMtThread t = mThreads[i];
                        if (t.mThread.LoopThread_StartSubThread() != SZ_OK)
                        {
                            res = SZ_ERROR_THREAD;
                            Trace.MatchObjectWait(mThreads[0], "MtCoder_Code");
                            mThreads[0].mStopReading = true;
                            Trace.MatchObjectWait(mThreads[0], "MtCoder_Code");
                            break;
                        }
                    }

                    Event_Set(mThreads[0].mCanWrite);
                    Event_Set(mThreads[0].mCanRead);

                    for (int j = 0; j < i; j++)
                    {
                        mThreads[j].mThread.LoopThread_WaitSubThread();
                    }
                }

                for (uint i = 0; i < numThreads; i++)
                {
                    mThreads[i].CMtThread_CloseEvents();
                }

                return((res == SZ_OK) ? mRes : res);
            }
Exemple #4
0
            internal SRes MtThread_Process(out bool stop)
            {
                stop = true;
                if (Event_Wait(mCanRead) != 0)
                {
                    return(SZ_ERROR_THREAD);
                }

                CMtThread next = GET_NEXT_THREAD();

                Trace.MatchObjectWait(this, "MtThread_Process");
                if (mStopReading)
                {
                    next.mStopReading = true;
                    Trace.MatchObjectWait(this, "MtThread_Process");
                    return(Event_Set(next.mCanRead) == 0 ? SZ_OK : SZ_ERROR_THREAD);
                }
                Trace.MatchObjectWait(this, "MtThread_Process");

                {
                    long size     = mMtCoder.mBlockSize;
                    long destSize = mOutBufSize;

                    SRes res;
                    if ((res = CMtCoder.FullRead(mMtCoder.mInStream, mInBuf, ref size)) != SZ_OK)
                    {
                        return(res);
                    }

                    stop = (size != mMtCoder.mBlockSize);

                    Trace.MatchObjectWait(this, "MtThread_Process:2");
                    next.mStopReading = stop;
                    Trace.MatchObjectWait(this, "MtThread_Process:2");

                    if (Event_Set(next.mCanRead) != 0)
                    {
                        return(SZ_ERROR_THREAD);
                    }

                    if ((res = mMtCoder.mMtCallback.Code(mIndex, mOutBuf, ref destSize, mInBuf, size, stop)) != SZ_OK)
                    {
                        return(res);
                    }

                    mMtCoder.mMtProgress.MtProgress_Reinit(mIndex);

                    if (Event_Wait(mCanWrite) != 0)
                    {
                        return(SZ_ERROR_THREAD);
                    }

                    Trace.MatchObjectWait(this, "MtThread_Process:3");
                    if (mStopWriting)
                    {
                        Trace.MatchObjectWait(this, "MtThread_Process:3");
                        return(SZ_ERROR_FAIL);
                    }
                    Trace.MatchObjectWait(this, "MtThread_Process:3");

                    if (mMtCoder.mOutStream.Write(mOutBuf, destSize) != destSize)
                    {
                        return(SZ_ERROR_WRITE);
                    }

                    return(Event_Set(next.mCanWrite) == 0 ? SZ_OK : SZ_ERROR_THREAD);
                }
            }
Exemple #5
0
            // MtCoder_Construct
            internal CMtCoder()
            {
                mAlloc = null;

                mThreads = new CMtThread[NUM_MT_CODER_THREADS_MAX];
                for(int i = 0; i < mThreads.Length; i++)
                    mThreads[i] = new CMtThread(i, this);

                CriticalSection_Init(out mCS);
                CriticalSection_Init(out mMtProgress.mCS);
            }