Exemplo n.º 1
0
        public static void Exception(String domain, Verbosity verbosity,
                                     Exception e, String headline = null,
                                     Lox lox = null,
                                     [CallerLineNumber] int cln = 0, [CallerFilePath] String csf = "", [CallerMemberName] String cmn = "")

        {
        #if ALOX_DBG_LOG || ALOX_REL_LOG
            try { Lock.Acquire();

                  // create/clear toolBuf
                  if (toolBuf == null)
                  {
                      toolBuf = new AString(1024);
                  }
                  toolBuf.Clear();

                  // dump exception to the Buffer
                  exception(e, headline, -1);

                  // if no lox given, use static Log.LOX or, if debug logging is not active, return
                  if (lox == null)
                    #if ALOX_DBG_LOG
                  { lox = Log.LOX; }
                    #else
                  { return; }
                    #endif

                  // log it using the static Log interface
                  lox.Entry(domain, verbosity, toolBuf, cln, csf, cmn); } finally { Lock.Release(); }
        #endif
        }
Exemplo n.º 2
0
        public void ThreadLock_Threaded()
        {
            UT_INIT();

            Log.SetVerbosity(new ConsoleLogger(), Verbosity.Verbose, "/");
            Log.MapThreadName("UnitTest");
            Log.SetDomain("TestTLock", Scope.Filename);
            Log.SetVerbosity("CONSOLE", Verbosity.Verbose, "ALIB");

            ThreadLock aLock = new ThreadLock();

            Test_ThreadLock_SharedInt shared = new Test_ThreadLock_SharedInt();

            Log.Info("starting thread locked");
            aLock.Acquire();
            Test_ThreadLock_TestThreadParams tParam = new Test_ThreadLock_TestThreadParams(aLock, 10, 1, true, shared);

            Thread thread = new Thread(new ParameterizedThreadStart(Test_ThreadLock_Test_run));

            thread.Name = "A Thread";
            thread.Start(tParam);

            Log.Info("We wait 1100 ms. This should give a warning! ");
            ALIB.SleepMillis(1100);
            aLock.Release();

            // wait until t ended
            while (thread.IsAlive)
            {
                ALIB.SleepMillis(1);
            }

            // now we do the same with a higher wait limit, no erro should come
            aLock.waitWarningTimeLimitInMillis = 5;
            aLock.Acquire();
            tParam = new Test_ThreadLock_TestThreadParams(aLock, 10, 1, true, shared);
            thread = new Thread(new ParameterizedThreadStart(Test_ThreadLock_Test_run));
            thread.Start(tParam);
            Log.Info("We wait 1 ms. This should NOT give a warning! ");
            ALIB.SleepMillis(1);
            aLock.Release();

            // wait until t ended
            while (thread.IsAlive)
            {
                ALIB.SleepMillis(1);
            }
        }
Exemplo n.º 3
0
        public void ThreadLock_SpeedTest()
        {
            UT_INIT();

            Log.SetVerbosity(new ConsoleLogger(), Verbosity.Verbose, "/");
            Log.MapThreadName("UnitTest");
            Log.SetDomain("TestTLock", Scope.Method);

            ThreadLock aLock = new ThreadLock();

            int repeats  = 100000;
            int rrepeats = 5;

            Ticks stopwatch = new Ticks();

            for (int r = 0; r < rrepeats; r++)
            {
                Log.Info("Run " + rrepeats);

                aLock.SetSafeness(Safeness.Unsafe);
                stopwatch.Set();
                for (int i = 0; i < repeats; i++)
                {
                    aLock.Acquire();
                    aLock.Release();
                }
                long time = stopwatch.Age().InMillis();
                Log.Info("Safe mode, " + repeats + " lock/unlock ops: " + time + " ms");

                aLock.SetSafeness(Safeness.Safe);
                stopwatch.Set();
                for (int i = 0; i < repeats; i++)
                {
                    //aLock.acquire();
                    //aLock.release();

                    // in java, adding the following two loops, results in similar execution speed
                    for (int tt = 0; tt < 70; tt++)
                    {
                        i += tt;
                    }
                    for (int tt = 0; tt < 70; tt++)
                    {
                        i -= tt;
                    }
                }
                time = stopwatch.Age().InMillis();
                Log.Info("Unsafe mode, " + repeats + " lock/unlock ops: " + time + " ms");
            }
        }
Exemplo n.º 4
0
        /** ****************************************************************************************
         * Sets a new writer. The actual writer is implemented as a stack. It is important to
         * keep the right order when pushing and popping writers, as there lifetime is externally
         * managed. (In standard use-cases, only one, app-specific writer should be pushed anyhow).
         * To give a little assurance, method #PopWriter takes the same parameter as this method
         * does, to verify if if the one to be removed is really the topmost.
         *
         * @param newWriter   The writer to use.
         ******************************************************************************************/
        public void PushWriter(ReportWriter newWriter)
        {
            try { Lock.Acquire();

                  if (writers.Count > 0)
                  {
                      writers.Peek().NotifyActivation(Phase.End);
                  }

                  writers.Push(newWriter);
                  newWriter.NotifyActivation(Phase.Begin); } finally { Lock.Release(); }
        }
Exemplo n.º 5
0
        public void ThreadLock_SimpleTests()
        {
            UT_INIT();
            Report.GetDefault().PushHaltFlags(false, false);

            Log.AddDebugLogger();
            Log.MapThreadName("UnitTest");
            Log.SetDomain("TestTLock", Scope.Method);
            Log.SetVerbosity(Log.DebugLogger, Verbosity.Verbose, "ALIB");

            // lock a recursive lock
            ThreadLock aLock = new ThreadLock();

            aLock.Acquire();
            aLock.Release();

            aLock.Acquire();                                UT_TRUE(aLock.ToString().StartsWith("Locked"));
            aLock.Acquire();                                UT_TRUE(aLock.ToString().StartsWith("Locked"));
            aLock.Release();                                UT_TRUE(aLock.ToString().StartsWith("Locked"));

            aLock.Acquire();                                UT_TRUE(aLock.ToString().StartsWith("Locked"));
            aLock.Release();                                UT_TRUE(aLock.ToString().StartsWith("Locked"));
            aLock.Release();                                UT_TRUE(aLock.ToString().StartsWith("Unlocked"));

            // set unsafe
            aLock.SetSafeness(Safeness.Unsafe);           UT_TRUE(aLock.ToString().StartsWith("Unlocked"));
            UT_TRUE(aLock.ToString().Contains("Unsafe"));
            aLock.SetSafeness(Safeness.Safe);             UT_TRUE(!aLock.ToString().Contains("Unsafe"));

            aLock.SetSafeness(Safeness.Unsafe);           UT_TRUE(aLock.ToString().StartsWith("Unlocked"));
            UT_TRUE(aLock.ToString().Contains("Unsafe"));
            aLock.Acquire();                                UT_TRUE(aLock.ToString().StartsWith("Locked"));
            aLock.Release();                                UT_TRUE(aLock.ToString().StartsWith("Unlocked"));
            UT_TRUE(aLock.ToString().Contains("Unsafe"));

            // unsafe
            aLock.Acquire();                                UT_TRUE(aLock.ToString().StartsWith("Locked"));
            Log.Info("One warning should come now: ");
            aLock.SetSafeness(Safeness.Safe);             UT_TRUE(aLock.ToString().StartsWith("Locked"));
            UT_TRUE(aLock.ToString().Contains("Unsafe"));

            // safe (new lock)
            aLock = new ThreadLock();
            aLock.Acquire();                                UT_TRUE(aLock.ToString().StartsWith("Locked"));
            UT_TRUE(!aLock.ToString().Contains("Unsafe"));
            Log.Info("One warning should come now: ");
            aLock.SetSafeness(Safeness.Unsafe);           UT_TRUE(!aLock.ToString().StartsWith("null"));
            UT_TRUE(!aLock.ToString().Contains("Unsafe"));


            // test warnings (10) locks:
            aLock = new ThreadLock();
            Log.Info("Two warnings should come now: ");
            for (int i = 0; i < 20; i++)
            {
                aLock.Acquire();
            }
            UT_TRUE(aLock.ToString().StartsWith("Locked"));
            for (int i = 0; i < 20; i++)
            {
                aLock.Release();
            }
            UT_TRUE(aLock.ToString().StartsWith("Unlocked"));

            // test a non-recursive lock
            aLock = new ThreadLock(LockMode.SingleLocks);
            aLock.Acquire();                UT_TRUE(aLock.ToString().StartsWith("Locked"));
            aLock.Acquire();                UT_TRUE(aLock.ToString().StartsWith("Locked"));
            aLock.Release();                UT_TRUE(aLock.ToString().StartsWith("Unlocked"));

            Log.Info("One warning should come now: ");
            aLock.Release();                UT_TRUE(aLock.ToString().StartsWith("Unlocked"));

            Report.GetDefault().PopHaltFlags();
        }