Example #1
0
            public static IEnumerable ParallelMap(IApply action, IEnumerable seq)
            {
                if (seq == null)
                {
                    return(null);
                }
                var seq2     = ConvertToEnumerableObject(seq);
                var seq3     = seq2.AsParallel().AsOrdered();
                var specials = GetCurrentThread().SpecialStack;

                Func <object, object> wrapper = a =>
                {
                    // We want an empty threadcontext because threads may be reused
                    // and already have a broken threadcontext.
                    CurrentThreadContext = new ThreadContext(specials);
                    return(Funcall(action, a));
                };

                return(seq3.Select(wrapper));
            }
Example #2
0
            public static IEnumerable ParallelMap(IApply action, IEnumerable seq)
            {
                if (seq == null)
                {
                    return null;
                }
                var seq2 = ConvertToEnumerableObject(seq);
                var seq3 = seq2.AsParallel().AsOrdered();
                var specials = GetCurrentThread().SpecialStack;

                Func<object, object> wrapper = a =>
                {
                    // We want an empty threadcontext because threads may be reused
                    // and already have a broken threadcontext.
                    CurrentThreadContext = new ThreadContext(specials);
                    return Funcall(action, a);
                };

                return seq3.Select(wrapper);
            }
Example #3
0
        public static object TryResume(ThreadContext ctx, object eofValue)
        {
            var context = CheckGeneratorThreadContext(ctx);

            return(context.TryResume(eofValue));
        }
Example #4
0
        public static object Resume(ThreadContext ctx)
        {
            var context = CheckGeneratorThreadContext(ctx);

            return(context.Resume());
        }
Example #5
0
 public static object GetTaskResult(ThreadContext task)
 {
     return(task.GetResult());
 }
Example #6
0
 public static void ParallelEach(IApply action, IEnumerable seq)
 {
     var seq2 = ConvertToEnumerableObject(seq);
     var specials = GetCurrentThread().SpecialStack;
     ActionFunc wrapper = a =>
     {
         // We want an empty threadcontext because threads may be reused
         // and already have a broken threadcontext.
         CurrentThreadContext = new ThreadContext(specials);
         Funcall(action, a);
     };
     Parallel.ForEach(seq2, wrapper);
 }
Example #7
0
        public static GeneratorThreadContext CheckGeneratorThreadContext(ThreadContext ctx)
        {
            var context = ctx as GeneratorThreadContext;

            if (context == null)
            {
                throw new LispException("Thread is not a generator thread");
            }

            return context;
        }
Example #8
0
 public static object Resume(ThreadContext ctx)
 {
     var context = CheckGeneratorThreadContext(ctx);
     return context.Resume();
 }
Example #9
0
 public static object GetTaskResult(ThreadContext task)
 {
     return task.GetResult();
 }
Example #10
0
        public static object CreateThreadWithContext(ThreadFunc code, ThreadContext context, bool start)
        {
            ThreadStart wrapper = () =>
            {
                try
                {
                    CurrentThreadContext = context;
                    context.ThreadResult = code();
                }
                catch (InterruptException)
                {

                }
                catch (Exception ex)
                {
                    var ex2 = UnwindExceptionIntoNewException(ex);
                    PrintError(ex.ToString());
                    throw ex2;
                }
                finally
                {
                    CurrentThreadContext = null;
                }
            };

            var thread = new Thread(wrapper);
            context.Thread = thread;
            if (start)
            {
                context.Start();
            }

            return context;
        }
Example #11
0
        public static object CreateTaskWithContext(ThreadFunc code, ThreadContext context, bool start)
        {
            Func<object> wrapper = () =>
            {
                try
                {
                    CurrentThreadContext = context;
                    return code();
                }
                catch (InterruptException)
                {
                    return null;
                }
                catch (Exception ex)
                {
                    var ex2 = UnwindExceptionIntoNewException(ex);
                    PrintError(ex.ToString());
                    throw ex2;
                }
                finally
                {
                    CurrentThreadContext = null;
                }
            };

            var task = new Task<object>(wrapper);
            context.Task = task;
            if (start)
            {
                context.Start();
            }

            return context;
        }