Example #1
0
        private bool TerminateInternal(int timeoutMs, StateKind state, string action)
        {
            lock (myLock)
            {
                if (State == StateKind.Initialized)
                {
                    LogLog.Verbose(LogCategory, "Can't {1} '{0}', because it hasn't been started yet", Id, action);
                    CleanupInternal();
                    return(true);
                }

                if (State >= state)
                {
                    LogLog.Verbose(LogCategory, "Trying to {2} async processor '{0}' but it's in state '{1}'", Id, State, action);
                    return(true);
                }

                State = state;
                Monitor.Pulse(myLock);
            }

            var res = myAsyncProcessingThread.Join(timeoutMs);

            if (!res)
            {
                LogLog.Warn($"Async processor {Id} hasn't finished in ${timeoutMs} ms. Trying to abort thread.");
                LogLog.Catch(() => myAsyncProcessingThread.Abort());
            }

            CleanupInternal();
            return(res);
        }
Example #2
0
        private static IntPtr AllocateMemory(int allocSize)
        {
            //can't use ILog.Verbose here because logger is closed to UnsafeWriter
            LogLog.Verbose(LogCategory, "New memory block allocated, size: {0:N0} bytes, total allocated blocks: {1}, used: {2}", allocSize, SampleCount(), SampleUsed());
            var pointer = Marshal.AllocHGlobal(allocSize);

            if (pointer == IntPtr.Zero)
            {
                ErrorOomOldMono();
            }
            return(pointer);
        }
Example #3
0
        public void Clear()
        {
            Assertion.Require(Thread.CurrentThread != myAsyncProcessingThread, "Thread.CurrentThread != myAsyncProcessingThread");

            lock (myLock)
            {
                LogLog.Verbose(LogCategory, "Cleaning '{0}', state={1}", Id, State);
                if (State >= StateKind.Stopping)
                {
                    return;
                }

                WaitProcessingFinished();

                Reset(ChunkSize);
                myAllDataProcessed = true;
            }
        }
Example #4
0
        /// <summary>
        /// Starts async processing of queue.
        /// </summary>
        public void Start()
        {
            lock (myLock)
            {
                if (State != StateKind.Initialized)
                {
                    LogLog.Verbose(LogCategory, "Trying to START async processor '{0}' but it's in state '{1}'", Id, State);
                    return;
                }

                State = StateKind.AsyncProcessing;

                myAsyncProcessingThread = new Thread(ThreadProcCatchAbort)
                {
                    Name = Id, IsBackground = true
                };
                myAsyncProcessingThread.Start();
            }
        }