Beispiel #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));
            }
Beispiel #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);
            }
Beispiel #3
0
        public static object TryResume(ThreadContext ctx, object eofValue)
        {
            var context = CheckGeneratorThreadContext(ctx);

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

            return(context.Resume());
        }
Beispiel #5
0
 public static object GetTaskResult(ThreadContext task)
 {
     return(task.GetResult());
 }
Beispiel #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);
 }
Beispiel #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;
        }
Beispiel #8
0
 public static object Resume(ThreadContext ctx)
 {
     var context = CheckGeneratorThreadContext(ctx);
     return context.Resume();
 }
Beispiel #9
0
 public static object GetTaskResult(ThreadContext task)
 {
     return task.GetResult();
 }
Beispiel #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;
        }
Beispiel #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;
        }