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)); }
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); }
public static object TryResume(ThreadContext ctx, object eofValue) { var context = CheckGeneratorThreadContext(ctx); return(context.TryResume(eofValue)); }
public static object Resume(ThreadContext ctx) { var context = CheckGeneratorThreadContext(ctx); return(context.Resume()); }
public static object GetTaskResult(ThreadContext task) { return(task.GetResult()); }
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); }
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; }
public static object Resume(ThreadContext ctx) { var context = CheckGeneratorThreadContext(ctx); return context.Resume(); }
public static object GetTaskResult(ThreadContext task) { return task.GetResult(); }
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; }
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; }