Beispiel #1
0
 public void Dispose()
 {
     m_port.Dispose();
     Portable.CloseHandle(m_scheduleSem);
     m_startEvent.Close();
     m_stopEvent.Close();
 }
Beispiel #2
0
 internal void ScheduleSend(Node node)
 {
     lock (m_scheduledSends)
     {
         if (!m_scheduledSends.Contains(node))
         {
             m_scheduledSends.Add(node);
             Portable.ReleaseSemaphore(m_scheduleSem, 1);
         }
     }
 }
Beispiel #3
0
 internal void CancelSend(Node node)
 {
     lock (m_scheduledSends)
     {
         if (m_scheduledSends.Contains(node))
         {
             m_scheduledSends.Remove(node);
             Portable.WaitOne(m_scheduleSem, Timeout.Infinite);
         }
     }
 }
Beispiel #4
0
        private void Dispatcher()
        {
            m_startEvent.Set();

            IntPtr[] handles = { m_stopEvent.Handle, m_scheduleSem };


            while (true)
            {
                int res = Portable.WaitAny(handles, 2000);

                if (res == 0)
                {
                    return;
                }
                else if (res == 1)
                {
                    Node node = GetScheduledNode();

                    Debug.Assert(node != null);

                    if (SendToSlave(node))
                    {
                        PollSlave(node);
                    }
                    else
                    {
                        ScheduleSend(node);
                    }
                }
                else if (res == Portable.WAIT_TIMEOUT)
                {
                    Node[] nodes = null;

                    lock (this)
                    {
                        nodes = m_nodes.ToArray();
                    }

                    if (nodes != null)
                    {
                        for (int i = 0; i < nodes.Length; ++i)
                        {
                            PollSlave(nodes[i]);
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public void Stop()
        {
            Logging.Trace(TraceEventType.Information, "Stopping bus dispatcher");

            m_stopEvent.Set();
            m_dispatchThread.Join();
            m_port.Close();

            m_scheduledSends.Clear();
            m_nodes.Clear();

            while (Portable.WaitOne(m_scheduleSem, 0))
            {
                ;
            }
        }