コード例 #1
0
        public IExecutorThread Create(IExecutor executor, RunData data, IThreadStarter starter)
        {
            IExecutorThread thread = new ExecutorThreadImpl(executor, data);

            starter.OnStarted(thread);
            return(thread);
        }
コード例 #2
0
 public FixedSizeThreadPool(FixedSizeThreadPoolOption option)
 {
     this.option        = option;
     this.threadStarter = CreateThreadStarter();
     for (int i = 0; i < option.Size; i++)
     {
         this.threadStarter.StartThread(ExecuteWorkers);
     }
 }
コード例 #3
0
        public void Create()
        {
            IExecutor      executor = Stub <IExecutor>();
            IThreadStarter starter  = Stub <IThreadStarter>();
            RunData        data     = new RunData();

            starter.Expect((m) => m.OnStarted(Arg <IExecutorThread> .Is.NotNull));

            IExecutorThread thread = VerifyTarget(() => target.Create(executor, data, starter));

            Assert.AreEqual(data, thread.GetRunData());
            Assert.AreEqual(executor, thread.GetExecutor());
            Assert.IsNull(thread.GetTask());
        }
コード例 #4
0
        public MemoryMappedCommunicator(IThreadStarter threadStarter, string mappingBaseName, bool isHost)
        {
            this.MappingBaseName = mappingBaseName;
            this.IsHost          = isHost;
            MappingNameSend      = MappingBaseName + ".HostSend";
            MappingNameReceive   = MappingBaseName + ".HostReceive";
            if (!IsHost)
            {
                var temp = MappingNameSend;
                MappingNameSend    = MappingNameReceive;
                MappingNameReceive = temp;
            }
            disposedValue      = false;
            run                = true;
            receiverThreadDone = false;

            long totalMappedMemory = MemoryCapacity * StreamBufferCount;

            sendFile       = MemoryMappedFile.CreateOrOpen(MappingNameSend, totalMappedMemory, MemoryMappedFileAccess.ReadWrite);
            receiveFile    = MemoryMappedFile.CreateOrOpen(MappingNameReceive, totalMappedMemory, MemoryMappedFileAccess.ReadWrite);
            sendStreams    = new MemoryMappedViewStream[StreamBufferCount];
            receiveStreams = new MemoryMappedViewStream[StreamBufferCount];

            long memoryPerBuffer = MemoryCapacity;

            for (int i = 0; i < StreamBufferCount; i++)
            {
                sendStreams[i]    = sendFile.CreateViewStream(i * memoryPerBuffer, memoryPerBuffer, MemoryMappedFileAccess.ReadWrite);
                receiveStreams[i] = receiveFile.CreateViewStream(i * memoryPerBuffer, memoryPerBuffer, MemoryMappedFileAccess.ReadWrite);
            }
            sendCurrentIndex    = 0;
            receiveCurrentIndex = 0;
            TotalSendCount      = 0;
            totalReceiveCount   = 0;

            receiverLocalMemory = new MemoryStream(new byte[MemoryCapacity], 0, MemoryCapacity, true, true);

            sendSync    = new Sync(MappingNameSend);
            receiveSync = new Sync(MappingNameReceive);

            receiverDelegates = new List <Action <MemoryStream> >();

            Thread.ThreadStart startInfo = new Thread.ThreadStart(ReceiveThread, this);
            receiverThread = threadStarter.CreateThread(startInfo);
        }
コード例 #5
0
 public void AddThreadStarter(IThreadStarter threadStarter)
 {
     this.threadStarter = threadStarter;
 }
コード例 #6
0
 public LockQueued(IThreadStarter starter, ManualResetEvent terminateEvent = null)
 {
     events[0] = sendEvent = new AutoResetEvent(false);
     events[1] = terminateEvent ?? new ManualResetEvent(false);
     starter.Start(ThreadRun);
 }
コード例 #7
-1
 public IExecutorThread Create(IExecutor executor, RunData data, IThreadStarter starter)
 {
     IExecutorThread thread = new ExecutorThreadImpl(executor, data);
     starter.OnStarted(thread);
     return thread;
 }