protected Worker(string workerName, WaitHandle stopSignal, IThreadFactory threadFactory, IWorkerMonitor workerMonitor) { this.threadFactory = threadFactory; this.workerName = workerName; this.stopSignal = stopSignal; this.workerMonitor = workerMonitor; }
public SingleThreadEventLoop(IEventLoopGroup parent, IThreadFactory threadFactory, IRejectedExecutionHandler rejectedHandler, TimeSpan breakoutInterval) : base(parent, threadFactory, false, int.MaxValue, rejectedHandler) { _emptyEvent = new ManualResetEventSlim(false, 1); _breakoutNanosInterval = PreciseTime.ToDelayNanos(breakoutInterval); Start(); }
public CheckTriggersQueueFeeder( WaitHandle stopSignal, JobQueue <ProjectRelatedJob> buildQueue, IThreadFactory threadFactory, IWorkerMonitor workerMonitor, IProjectRegistry projectRegistry) : base("CheckTriggersQueueFeeder", stopSignal, threadFactory, workerMonitor) { this.projectRegistry = projectRegistry; this.checkTriggersQueue = new JobQueue <ProjectRelatedJob> ("Check triggers queue", stopSignal); for (int i = 0; i < checkTriggersWorkersCount; i++) { CheckTriggersWorker worker = new CheckTriggersWorker( string.Format( CultureInfo.InvariantCulture, "CheckTriggersWorker {0}", i), checkTriggersQueue, buildQueue, threadFactory, projectRegistry, workerMonitor); checkTriggersQueue.AddWorker(worker); } checkTriggersQueue.StartWorkers(); }
public PausingWrapper(Action pausableMethod, IThreadFactory simpleThreadFactory) { this.pausableMethod = pausableMethod; //Note: this is deliberately not a background thread, since this could potentially cause slowdowns due to the OS not scheduling this thread fast enough thread = simpleThreadFactory.CreateThread(simulationThread); thread.Start(); }
/// <summary> /// Start the given agent runner on a new thread. /// </summary> /// <param name="runner"> the agent runner to start </param> /// <param name="threadFactory"> the factory to use to create the thread.</param> /// <returns> the new thread that has been started.</returns> public static Thread StartOnThread(AgentRunner runner, IThreadFactory threadFactory) { var thread = threadFactory.NewThread(runner.Run); thread.Name = runner.Agent().RoleName(); thread.Start(); return(thread); }
public SingleThreadExecutor(ShutdownMode shutdownMode, IThreadFactory threadFactory) { this.shutdownMode = shutdownMode; ThreadStart start = new ThreadStart(RunWorker); workerThread = threadFactory.CreateOrGetThread(start); workerThread.Start(); }
protected SingleThreadEventLoopBase(IEventLoopGroup parent, IThreadFactory threadFactory, bool addTaskWakesUp, int maxPendingTasks, IRejectedExecutionHandler rejectedHandler) : base(parent, threadFactory, addTaskWakesUp, maxPendingTasks, rejectedHandler) { #if DEBUG _tailTasks = NewTaskQueue(maxPendingTasks); #endif }
/// <summary> /// Start the given agent runner on a new thread. /// </summary> /// <param name="runner"> the agent runner to start </param> /// <param name="threadFactory"> the factory to use to create the thread.</param> /// <returns> the new thread that has been started.</returns> public static Thread StartOnThread(AgentRunner runner, IThreadFactory threadFactory) { var thread = threadFactory.NewThread(runner.Run); ConfigureThread(thread, runner); thread.Start(); return(thread); }
[Test] public void ThreadFactoryReturnsFactoryGivenInConstructor() { IThreadFactory tf = MockRepository.GenerateStub <IThreadFactory>(); ExecutorService = new ThreadPoolExecutor(1, 2, Delays.Long, new ArrayBlockingQueue <IRunnable>(10), tf, new NoOpHandler()); Assert.AreSame(tf, ExecutorService.ThreadFactory); JoinPool(ExecutorService); }
/// <summary> /// Initializes a new instance of the <see cref="PinsBehavior" /> class. /// </summary> /// <param name="configurations">The configurations.</param> /// <param name="threadFactory">The thread factory.</param> protected PinsBehavior(IEnumerable <PinConfiguration> configurations, IThreadFactory threadFactory) { this.Configurations = configurations.ToArray(); this.thread = threadFactory.Create(); this.timer = Timer.Create(); this.interval = TimeSpan.FromMilliseconds(250); this.timer.Tick += this.OnTimer; }
/// <summary> /// Initializes a new instance of the <see cref="Pca9685Device" /> class. /// </summary> /// <param name="connection">The I2C connection.</param> /// <param name="threadFactory">The thread factory.</param> /// <param name="pca9685DeviceReporter">The pca9685 device reporter.</param> public Pca9685Device(I2cDeviceConnection connection, IThreadFactory threadFactory = null, IPca9685DeviceReporter pca9685DeviceReporter = null) { this.connection = connection; this.pca9685DeviceReporter = pca9685DeviceReporter; this.thread = ThreadFactory.EnsureThreadFactory(threadFactory).Create(); this.pca9685DeviceReporter?.Resetting(); this.WriteRegister(Register.Mode1, 0x00); }
protected SingleThreadEventLoopBase(IEventLoopGroup parent, IThreadFactory threadFactory, bool addTaskWakesUp, IQueue <IRunnable> taskQueue, IQueue <IRunnable> tailTaskQueue, IRejectedExecutionHandler rejectedHandler) : base(parent, threadFactory, addTaskWakesUp, taskQueue, rejectedHandler) { if (tailTaskQueue is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.tailTaskQueue); } _tailTasks = tailTaskQueue; }
public HttpQueryApplication(ISettings settings, Context context, IThreadFactory receiver_thread_factory) { settings_ = settings; socket_ = context.Socket(SocketType.DEALER); receiver_thread_factory_ = receiver_thread_factory; context_ = context; running_ = false; futures_ = new AsyncResponseMap(); request_id_ = 1; logger_ = HttpQueryLogger.ForCurrentProcess; }
public CheckTriggersWorker( string workerName, JobQueue <ProjectRelatedJob> jobQueue, JobQueue <ProjectRelatedJob> buildQueue, IThreadFactory threadFactory, IProjectRegistry projectRegistry, IWorkerMonitor workerMonitor) : base(workerName, jobQueue, threadFactory, workerMonitor) { this.buildQueue = buildQueue; this.projectRegistry = projectRegistry; }
public HeadlessService( IProjectRegistry projectRegistry, IThreadFactory threadFactory, IWorkerMonitor workerMonitor, IHeadlessLogger headlessLogger) { this.projectRegistry = projectRegistry; this.threadFactory = threadFactory; this.workerMonitor = workerMonitor; this.headlessLogger = headlessLogger; }
/// <summary> /// Initializes a new instance of the <see cref="I2cDriver" /> class. /// </summary> /// <param name="sdaPin">The SDA pin.</param> /// <param name="sclPin">The SCL pin.</param> /// <param name="threadFactory">The thread factory.</param> /// <exception cref="InvalidOperationException">Unable to access device memory.</exception> public I2cDriver(ProcessorPin sdaPin, ProcessorPin sclPin, IThreadFactory threadFactory = null) { this.sdaPin = sdaPin; this.sclPin = sclPin; this.thread = ThreadFactory.EnsureThreadFactory(threadFactory).Create(); var bscBase = GetBscBase(sdaPin, sclPin); var memoryFile = Interop.Open("/dev/mem", Interop.ORdwr + Interop.OSync); try { this.gpioAddress = Interop.Mmap( IntPtr.Zero, Interop.Bcm2835BlockSize, Interop.ProtRead | Interop.ProtWrite, Interop.MapShared, memoryFile, GetProcessorGpioAddress(Board.Current.Processor)); this.bscAddress = Interop.Mmap( IntPtr.Zero, Interop.Bcm2835BlockSize, Interop.ProtRead | Interop.ProtWrite, Interop.MapShared, memoryFile, bscBase); } finally { Interop.Close(memoryFile); } if (this.bscAddress == (IntPtr)Interop.MapFailed) { throw new InvalidOperationException("Unable to access device memory"); } // Set the I2C pins to the Alt 0 function to enable I2C access on them // remembers if the values were actually changed to clear them or not upon dispose this.wasSdaPinSet = this.SetPinMode((uint)(int)sdaPin, Interop.Bcm2835GpioFselAlt0); // SDA this.wasSclPinSet = this.SetPinMode((uint)(int)sclPin, Interop.Bcm2835GpioFselAlt0); // SCL // Read the clock divider register var dividerAddress = this.bscAddress + (int)Interop.Bcm2835BscDiv; var divider = (ushort)SafeReadUInt32(dividerAddress); this.waitInterval = GetWaitInterval(divider); var addressAddress = this.bscAddress + (int)Interop.Bcm2835BscA; SafeWriteUInt32(addressAddress, (uint)this.currentDeviceAddress); }
public WorkerPoolWorker( int ordinal, IThreadFactory threadFactory, BlockingCollection <IDelivery> deliveries, IDeliveryProcessor connectedProcessor) : base(connectedProcessor) { this.ordinal = ordinal; this.deliveries = deliveries; thread = threadFactory.Create(StartTakingMessages); }
public BuildWorker( string workerName, JobQueue <ProjectRelatedJob> buildQueue, IThreadFactory threadFactory, IProjectRegistry projectRegistry, IWorkerMonitor workerMonitor, IHeadlessLogger headlessLogger) : base(workerName, buildQueue, threadFactory, workerMonitor) { this.projectRegistry = projectRegistry; this.headlessLogger = headlessLogger; }
public WorkerPoolWorker( int ordinal, IThreadFactory threadFactory, BlockingCollection<IDelivery> deliveries, IDeliveryProcessor connectedProcessor) : base(connectedProcessor) { this.ordinal = ordinal; this.deliveries = deliveries; thread = threadFactory.Create(StartTakingMessages); }
public void ConstructorChokesOnNullThreadFactory() { const string expected = "threadFactory"; const IThreadFactory f = null; var e = Assert.Throws <ArgumentNullException>( () => new ThreadPoolExecutor(1, 2, Delays.Long, new ArrayBlockingQueue <IRunnable>(10), f)); Assert.That(e.ParamName, Is.EqualTo(expected)); e = Assert.Throws <ArgumentNullException>( () => new ThreadPoolExecutor(1, 2, Delays.Long, new ArrayBlockingQueue <IRunnable>(10), f, new NoOpHandler())); Assert.That(e.ParamName, Is.EqualTo(expected)); }
/// <summary> /// Initializes a new instance of the <see cref="GpioConnectionDriver" /> class. /// </summary> /// <param name="threadFactory">The thread factory.</param> public GpioConnectionDriver(IThreadFactory threadFactory = null) { this.thread = ThreadFactory.EnsureThreadFactory(threadFactory).Create(); using (var memoryFile = UnixFile.Open("/dev/mem", UnixFileMode.ReadWrite | UnixFileMode.Synchronized)) { this.gpioAddress = MemoryMap.Create( IntPtr.Zero, Interop.Bcm2835BlockSize, MemoryProtection.ReadWrite, MemoryFlags.Shared, memoryFile.Descriptor, GetProcessorBaseAddress(Board.Current.Processor)); } }
public void SetUp() { target = new ExecutorLauncherImpl(); threadFactory = Stub <IThreadFactory>(); args = Stub <ITestRunnerArgs>(); executor = Stub <IExecutor>(); threads = Stub <IList <IExecutorThread> >(); thread = Stub <IExecutorThread>(); target.ThreadFactory = threadFactory; target.Args = args; target.Executor = executor; target.Threads = threads; }
/// <summary> /// Initializes a new instance of the <see cref="PathService"/> class. /// </summary> /// <param name="engine">The engine.</param> /// <param name="threadFactory">The thread factory.</param> /// <param name="useThreadPoolForAsync">if set to <c>true</c> the thread pool will be used for async operation.</param> public PathService(IPathingEngine engine, IThreadFactory threadFactory, bool useThreadPoolForAsync) { Ensure.ArgumentNotNull(engine, "engine"); Ensure.ArgumentNotNull(threadFactory, "threadFactory"); _stopwatch = new Stopwatch(); _queue = new PriorityQueueFifo <IPathRequest>(StartQueueSize, QueueType.Max); _engine = engine; _threadPoolSupported = useThreadPoolForAsync; #if !NETFX_CORE _threadFactory = threadFactory; #endif }
/// <summary>Creates a new instance of <see cref="SingleThreadEventExecutor"/>.</summary> /// <param name="parent">the <see cref="IEventExecutorGroup"/> which is the parent of this instance and belongs to it.</param> /// <param name="threadFactory">the <see cref="IThreadFactory"/> which will be used for the used <see cref="Thread"/>.</param> /// <param name="addTaskWakesUp"><c>true</c> if and only if invocation of <see cref="AddTask(IRunnable)"/> will wake up the executor thread.</param> /// <param name="maxPendingTasks">the maximum number of pending tasks before new tasks will be rejected.</param> /// <param name="rejectedHandler">the <see cref="IRejectedExecutionHandler"/> to use.</param> protected SingleThreadEventExecutor(IEventExecutorGroup parent, IThreadFactory threadFactory, bool addTaskWakesUp, int maxPendingTasks, IRejectedExecutionHandler rejectedHandler) : this(parent, addTaskWakesUp, rejectedHandler) { if (threadFactory is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.threadFactory); } _maxPendingTasks = Math.Max(16, maxPendingTasks); _taskQueue = NewTaskQueue(_maxPendingTasks); _blockingTaskQueue = _taskQueue as IBlockingQueue <IRunnable>; _thread = NewThread(threadFactory); }
internal DispatcherEventLoop(IEventLoopGroup parent, IThreadFactory threadFactory) : base(parent, threadFactory, RejectedExecutionHandlers.Reject(), DefaultBreakoutInterval) { if (parent is null) { ThrowHelper.ThrowArgumentNullException(ExceptionArgument.parent); } string pipeName = "DotNetty_" + Guid.NewGuid().ToString("n"); PipeName = (PlatformApi.IsWindows ? @"\\.\pipe\" : "/tmp/") + pipeName; Start(); }
/// <summary> /// Initializes a new instance of the <see cref="PathService"/> class. /// </summary> /// <param name="engine">The engine.</param> /// <param name="threadFactory">The thread factory.</param> /// <param name="useThreadPoolForAsync">if set to <c>true</c> the thread pool will be used for async operation.</param> public PathService(IPathingEngine engine, IThreadFactory threadFactory, bool useThreadPoolForAsync) { Ensure.ArgumentNotNull(engine, "engine"); Ensure.ArgumentNotNull(threadFactory, "threadFactory"); _stopwatch = new Stopwatch(); _queue = new PriorityQueueFifo<IPathRequest>(StartQueueSize, QueueType.Max); _engine = engine; _threadPoolSupported = useThreadPoolForAsync; #if !NETFX_CORE _threadFactory = threadFactory; #endif }
/// <summary> /// Initializes a new instance of the <see cref="DhtDevice" /> class. /// </summary> /// <param name="pin">The pin.</param> /// <param name="autoStart">if set to <c>true</c>, DHT is automatically started. Default value is <c>true</c>.</param> /// <param name="threadFactory">The thread factory.</param> /// <param name="dhtDeviceReporter">The DHT device reporter.</param> protected DhtDevice(IInputOutputBinaryPin pin, bool autoStart = true, IThreadFactory threadFactory = null, IDhtDeviceReporter dhtDeviceReporter = null) { this.thread = ThreadFactory.EnsureThreadFactory(threadFactory).Create(); this.pin = pin; this.dhtDeviceReporter = dhtDeviceReporter; if (autoStart) { this.Start(); } else { this.Stop(); } }
/// <summary> /// Initializes a new instance of the <see cref="HcSr04Device" /> class. /// </summary> /// <param name="triggerPin">The trigger pin.</param> /// <param name="echoPin">The echo pin.</param> /// <param name="threadFactory">The thread factory.</param> public HcSr04Device(IOutputBinaryPin triggerPin, IInputBinaryPin echoPin, IThreadFactory threadFactory = null) { this.triggerPin = triggerPin; this.echoPin = echoPin; this.thread = ThreadFactory.EnsureThreadFactory(threadFactory).Create(); this.SetTimeout(DefaultTimeout); try { this.GetDistance(); } catch { } }
[Test] public void ThreadFactorySetterSetsTheThreadFactory() { IThreadFactory tf = MockRepository.GenerateStub <IThreadFactory>(); tf.Stub(f => f.NewThread(Arg <IRunnable> .Is.NotNull)).Do( new Delegates.Function <Thread, IRunnable>(r => ThreadManager.NewManagedThread(r.Run))); var es = ExecutorService; es.ThreadFactory = tf; es.PreStartCoreThread(); Assert.AreEqual(tf, es.ThreadFactory); tf.AssertWasCalled(f => f.NewThread(Arg <IRunnable> .Is.NotNull)); JoinPool(es); ThreadManager.JoinAndVerify(); }
public ThreadPool(IThreadFactory factory, IThreadPoolCounter counter) { if (factory == null) { throw new ArgumentNullException(nameof(factory)); } if (counter == null) { throw new ArgumentNullException(nameof(counter)); } _factory = factory; _counter = counter; _allThreads = new ConcurrentDictionary <IThread, IThread>(); }
public ThreadService(IRepository <User> userRepository, IRepository <Thread> threadRepository, IRepository <Post> postRepository, IThreadFactory threadFactory, IUnitOfWork unitOfWork) { Guard.WhenArgument(userRepository, "userRepository cannot be null").IsNull().Throw(); Guard.WhenArgument(threadRepository, "threadRepository cannot be null").IsNull().Throw(); Guard.WhenArgument(postRepository, "postRepository cannot be null").IsNull().Throw(); Guard.WhenArgument(threadFactory, "userFactory cannot be null").IsNull().Throw(); Guard.WhenArgument(unitOfWork, "unitOfWork cannot be null").IsNull().Throw(); this.userRepository = userRepository; this.threadRepository = threadRepository; this.postRepository = postRepository; this.threadFactory = threadFactory; this.unitOfWork = unitOfWork; }
protected LoopExecutor(IEventLoopGroup parent, IThreadFactory threadFactory, IRejectedExecutionHandler rejectedHandler, TimeSpan breakoutInterval) : base(parent, threadFactory, false, int.MaxValue, rejectedHandler) { _writeRequestPool = new ThreadLocalPool <WriteRequest>(s_valueFactory); _preciseBreakoutInterval = ToPreciseTime(breakoutInterval); _loop = new Loop(); _asyncHandle = new Async(_loop, OnCallbackAction, this); _timerHandle = new Timer(_loop, OnCallbackAction, this); _loopRunStart = new ManualResetEventSlim(false, 1); if (SharedConstants.False >= (uint)Interlocked.Exchange(ref s_startTimeInitialized, SharedConstants.True)) { _loop.UpdateTime(); s_initialTime = _loop.Now; } }
public static void Initialize(IThreadFactory threadFactory) { s_ThreadFactory = threadFactory; }
/// <summary> /// Initializes a new instance of the <see cref="PathService"/> class. /// </summary> /// <param name="engine">The engine.</param> /// <param name="threadFactory">The thread factory.</param> public PathService(IPathingEngine engine, IThreadFactory threadFactory) : this(engine, threadFactory, true) { }
/// <summary> /// Creates a new <see cref="ThreadPoolExecutor"/> with the given initial /// parameters and default <see cref="RejectedExecutionException"/>. /// </summary> /// <param name="corePoolSize">the number of threads to keep in the pool, even if they are idle.</param> /// <param name="maximumPoolSize">the maximum number of threads to allow in the pool.</param> /// <param name="keepAliveTime"> /// When the number of threads is greater than /// <see cref="CorePoolSize"/>, this is the maximum time that excess idle threads /// will wait for new tasks before terminating. /// </param> /// <param name="workQueue"> /// The queue to use for holding tasks before they /// are executed. This queue will hold only the <see cref="IRunnable"/> /// tasks submitted by the <see cref="AbstractExecutorService.Execute(IRunnable)"/> method. /// </param> /// <param name="threadFactory"> /// <see cref="IThreadFactory"/> to use for new thread creation. /// </param> /// <exception cref="System.ArgumentOutOfRangeException"> /// If <paramref name="corePoolSize"/> or <paramref name="keepAliveTime"/> is less than zero, or if <paramref name="maximumPoolSize"/> /// is less than or equal to zero, or if <paramref name="corePoolSize"/> is greater than <paramref name="maximumPoolSize"/> /// </exception> /// <exception cref="System.ArgumentNullException">if <paramref name="workQueue"/> or <paramref name="threadFactory"/> is null</exception> public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, TimeSpan keepAliveTime, IBlockingQueue<IRunnable> workQueue, IThreadFactory threadFactory) : this(corePoolSize, maximumPoolSize, keepAliveTime, workQueue, threadFactory, _defaultRejectedExecutionHandler) { }
public void SetUp() { target = new ExecutorLauncherImpl(); threadFactory = Stub<IThreadFactory>(); args = Stub<ITestRunnerArgs>(); executor = Stub<IExecutor>(); threads = Stub<IList<IExecutorThread>>(); thread = Stub<IExecutorThread>(); target.ThreadFactory = threadFactory; target.Args = args; target.Executor = executor; target.Threads = threads; }
/// <summary> /// Initializes a new instance of the <see cref="PathService"/> class. /// </summary> /// <param name="engine">The engine.</param> /// <param name="directPather">The direct pather.</param> /// <param name="threadFactory">The thread factory.</param> public PathService(IPathingEngine engine, IDirectPather directPather, IThreadFactory threadFactory) : this(engine, directPather, threadFactory, true) { }
/// <summary> Creates a new <see cref="ThreadPoolExecutor"/> with the given initial /// parameters. /// /// </summary> /// <param name="corePoolSize">the number of threads to keep in the pool, even if they are idle.</param> /// <param name="maximumPoolSize">the maximum number of threads to allow in the pool.</param> /// <param name="keepAliveTime"> /// When the number of threads is greater than /// <see cref="CorePoolSize"/>, this is the maximum time that excess idle threads /// will wait for new tasks before terminating. /// </param> /// <param name="workQueue"> /// The queue to use for holding tasks before they /// are executed. This queue will hold only the <see cref="IRunnable"/> /// tasks submitted by the <see cref="AbstractExecutorService.Execute(IRunnable)"/> method. /// </param> /// <param name="threadFactory"> /// <see cref="IThreadFactory"/> to use for new thread creation. /// </param> /// <param name="handler"> /// The <see cref="IRejectedExecutionHandler"/> to use when execution is blocked /// because the thread bounds and queue capacities are reached. /// </param> /// <exception cref="System.ArgumentOutOfRangeException"> /// If <paramref name="corePoolSize"/> or <paramref name="keepAliveTime"/> is less than zero, or if <paramref name="maximumPoolSize"/> /// is less than or equal to zero, or if <paramref name="corePoolSize"/> is greater than <paramref name="maximumPoolSize"/> /// </exception> /// <exception cref="System.ArgumentNullException">if <paramref name="workQueue"/>, <paramref name="handler"/>, or <paramref name="threadFactory"/> is null</exception> public ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, TimeSpan keepAliveTime, IBlockingQueue<IRunnable> workQueue, IThreadFactory threadFactory, IRejectedExecutionHandler handler) { if (corePoolSize < 0) { throw new ArgumentOutOfRangeException("corePoolSize", corePoolSize, "core pool size cannot be less than zero."); } if (maximumPoolSize <= 0) { throw new ArgumentOutOfRangeException("maximumPoolSize", maximumPoolSize, "maximum pool size must be greater than zero"); } if (maximumPoolSize < corePoolSize) { throw new ArgumentException("maximum pool size, " + maximumPoolSize + " cannot be less than core pool size, " + corePoolSize + ".", "maximumPoolSize"); } if (keepAliveTime.Ticks < 0) { throw new ArgumentOutOfRangeException("keepAliveTime", keepAliveTime, "keep alive time must be greater than or equal to zero."); } if (workQueue == null) { throw new ArgumentNullException("workQueue"); } if (threadFactory == null) { throw new ArgumentNullException("threadFactory"); } if (handler == null) { throw new ArgumentNullException("handler"); } _corePoolSize = corePoolSize; _maximumPoolSize = maximumPoolSize; _workQueue = workQueue; KeepAliveTime = keepAliveTime; _threadFactory = threadFactory; _rejectedExecutionHandler = handler; _termination = _mainLock.NewCondition(); }
/// <summary> /// create a new ThreadPoolTaskExecutor /// </summary> public ThreadPoolTaskExecutor() { _threadFactory = this; }