示例#1
0
        /** this starts the worker threads and then waits for their results.
         */
        private static List <string> _Get_egs_branches_threaded(Changeset cs,
                                                                ChangeTypeToConsiderDelegate op)
        {
            System.Threading.Thread[] threads;
            _args args = new _args();

            {
                int cnt = FIND_THREAD_COUNT;
                if (cnt < 1)
                {
                    cnt = Environment.ProcessorCount;
                    if (cnt < 1)
                    {
                        cnt = 2;
                    }
                }
                threads = new System.Threading.Thread[cnt];
            }

            args.itemBranches = new List <string>();
            args.rwlock       = new System.Threading.ReaderWriterLock();
            args.changesLen   = cs.Changes.Length;
            args.changes      = cs.Changes;
            args.op           = op;

            for (int i = 0; i < threads.Length; ++i)
            {
                threads[i]          = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(_egsbranches_worker));
                threads[i].Priority = System.Threading.ThreadPriority.Lowest;
                threads[i].Start(args);
            }

            for (int i = 0; i < threads.Length; ++i)
            {
                threads[i].Join();
            }

            return(args.itemBranches);
        }
        /** this starts the worker threads and then waits for their results.
         */
        private static List <string> _get_egs_branches_threaded(Changeset cs)
        {
            System.Threading.Thread[] threads = new System.Threading.Thread[8];
            _args args = new _args();

            args.itemBranches = new List <string>();
            args.rwlock       = new System.Threading.ReaderWriterLock();
            args.changesLen   = cs.Changes.Length;
            args.changes      = cs.Changes;

            for (int i = 0; i < threads.Length; ++i)
            {
                threads[i]          = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(_egsbranches_worker));
                threads[i].Priority = System.Threading.ThreadPriority.Lowest;
                threads[i].Start(args);
            }

            for (int i = 0; i < threads.Length; ++i)
            {
                threads[i].Join();
            }

            return(args.itemBranches);
        }
 set => SetProperty(ref _args, value);
        private static void _egsbranches_worker(object o)
        {
            _args args = o as _args;
            bool  done = false;

            int res = System.Threading.Interlocked.Increment(ref args.ptr);

            done = res >= args.changesLen;

            while (!done)
            {
                string itemPath  = args.changes[res].Path;
                bool   found     = false;
                int    idx       = 0;
                int    itemCount = 0;

                try {
                    try {
                        args.rwlock.AcquireReaderLock(10 * 1000);                                 /* 10 second timeout. */
                        itemCount = args.itemBranches.Count;
                        for (int j = 0; j < args.itemBranches.Count; ++j)
                        {
                            /* the stupid branches are not case sensitive. */
                            idx = itemPath.IndexOf(args.itemBranches[j],
                                                   StringComparison.InvariantCultureIgnoreCase);
                            if (idx == 0)
                            {
                                found = true; break;
                            }
                        }
                    }
                    finally
                    {
                        args.rwlock.ReleaseReaderLock();
                    }
                } catch (ApplicationException) { /* we lost the lock. */ }

                if (!found)
                {
                    /* yeah steve, '/EGS8.2' sucks now doesn't it... */
                    string str = "/EGS/";

                    /* the stupid branches are not case sensitive. */
                    idx = itemPath.IndexOf(str, StringComparison.InvariantCultureIgnoreCase);

                    if (idx > 0)
                    {
                        itemPath = itemPath.Substring(0, idx + str.Length);
#if DEBUG
                        if (itemPath.IndexOf("$/IGT_0803/") == 0)
                        {
#endif
                        try {
                            try {
                                bool reallyFound = false;
                                args.rwlock.AcquireWriterLock(60 * 1000);                                                                         /* 1 minute timeout. */

                                if (itemCount != args.itemBranches.Count)
                                {
                                    /* look again. */
                                    for (int j = 0; j < args.itemBranches.Count; ++j)
                                    {
                                        idx = itemPath.IndexOf(args.itemBranches[j],
                                                               StringComparison.InvariantCultureIgnoreCase);
                                        if (idx == 0)
                                        {
                                            reallyFound = true; break;
                                        }
                                    }
                                }

                                if (!reallyFound)
                                {
                                    args.itemBranches.Add(itemPath);
                                }
                            }
                            finally { args.rwlock.ReleaseWriterLock(); }
                        }
                        catch (ApplicationException) { /* we lost the lock. */ }
#if DEBUG
                    }
                    else
                    {
                        Console.Error.WriteLine("'{0}' turned into '{1}'!",
                                                args.changes[res].Path,
                                                itemPath);
                    }
#endif
                    }
                }

                /* setup for the next loop. */
                res  = System.Threading.Interlocked.Increment(ref args.ptr);
                done = res >= args.changesLen;
            }
        }
示例#5
0
        private static void _egsbranches_worker(object o)
        {
            _args args = o as _args;
            bool  done = false;

            int res = System.Threading.Interlocked.Increment(ref args.ptr);

            done = res >= args.changesLen;

            while (!done)
            {
                string itemPath  = args.changes[res].Item.ServerItem;
                bool   found     = false;
                int    idx       = 0;
                int    itemCount = 0;

                /* skip all non-merge changesets. */
                if (args.op(args.changes[res]))
                {
                    /* this section compares the given path to the set we already have. */
                    try {
                        try {
                            args.rwlock.AcquireReaderLock(10 * 1000);                                             /* 10 second timeout. */

                            /* we use this count later on to 'detect'
                             * whether or not a sister branch added a branch to the list
                             * if one did, we need to re-check the list
                             * (they could have added the branch we're going to add
                             */
                            itemCount = args.itemBranches.Count;
                            for (int j = 0; j < args.itemBranches.Count; ++j)
                            {
                                /* the stupid branches are not case sensitive. */
                                idx = itemPath.IndexOf(args.itemBranches[j],
                                                       StringComparison.InvariantCultureIgnoreCase);
                                if (idx == 0)
                                {
                                    found = true; break;
                                }
                            }
                        }
                        finally
                        {
                            args.rwlock.ReleaseReaderLock();
                        }
                    } catch (ApplicationException) { /* we lost the lock. */ }

                    if (!found)
                    {
                        /* yeah steve, '/EGS8.2' sucks now doesn't it... */
                        string str = "/EGS/";

                        /* the stupid branches are not case sensitive. */
                        idx = itemPath.IndexOf(str, StringComparison.InvariantCultureIgnoreCase);

                        if (idx > 0)
                        {
                            itemPath = itemPath.Substring(0, idx + str.Length);
#if DEBUG
                            if (itemPath.IndexOf("$/IGT_0803/") == 0)
                            {
#endif
                            try {
                                try {
                                    bool reallyFound = false;
                                    /* 1 minute timeout. */
                                    args.rwlock.AcquireWriterLock(60 * 1000);

                                    if (itemCount != args.itemBranches.Count)
                                    {
                                        /* so one of our sister threads added a branch.
                                         * we have to look again.
                                         */
                                        for (int j = 0; j < args.itemBranches.Count; ++j)
                                        {
                                            idx = itemPath.IndexOf(args.itemBranches[j],
                                                                   StringComparison.InvariantCultureIgnoreCase);
                                            if (idx == 0)
                                            {
                                                reallyFound = true; break;
                                            }
                                        }
                                    }

                                    if (!reallyFound)
                                    {
                                        Logger.logger.DebugFormat("branch={0}", itemPath);
                                        args.itemBranches.Add(itemPath);
                                    }
                                }
                                finally
                                {
                                    /* i think this call can throw the ApplicationException
                                     * which is why there are 2 trys, but only one catch.
                                     * this finally is here to protect the rwlock.
                                     * we want to ensure that it will always get released
                                     * if feces contacts a fan...
                                     */
                                    args.rwlock.ReleaseWriterLock();
                                }
                            }
                            catch (ApplicationException) { /* we lost the lock. */ }
#if DEBUG
                        }
                        else
                        {
                            Console.Error.WriteLine("'{0}' turned into '{1}'!",
                                                    args.changes[res].Item.ServerItem,
                                                    itemPath);
                        }
#endif
                        }
                    }
                }

                /* setup for the next loop. */
                res  = System.Threading.Interlocked.Increment(ref args.ptr);
                done = res >= args.changesLen;
            }
        }