Пример #1
0
 public ThreadPoolCurrent(ThreadPool threadPool, EventHandler handler, int op)
 {
     _threadPool = threadPool;
     _handler = handler;
     operation = op;
     completedSynchronously = false;
 }
Пример #2
0
        public void update(EventHandler handler, int remove, int add)
        {
            lock(this)
            {
                Debug.Assert(!_destroyed);

                // Don't remove what needs to be added
                remove &= ~add;

                // Don't remove/add if already un-registered or registered
                remove &= handler._registered;
                add &= ~handler._registered;
                if(remove == add)
                {
                    return;
                }

                handler._registered &= ~remove;
                handler._registered |= add;

                if((add & SocketOperation.Read) != 0 && (handler._pending & SocketOperation.Read) == 0)
                {
                    handler._pending |= SocketOperation.Read;
                    executeNonBlocking(() =>
                        {
                            messageCallback(new ThreadPoolCurrent(this, handler, SocketOperation.Read));
                        });
                }
                else if((add & SocketOperation.Write) != 0 && (handler._pending & SocketOperation.Write) == 0)
                {
                    handler._pending |= SocketOperation.Write;
                    executeNonBlocking(() =>
                        {
                            messageCallback(new ThreadPoolCurrent(this, handler, SocketOperation.Write));
                        });
                }
            }
        }
Пример #3
0
 public void unregister(EventHandler handler, int op)
 {
     update(handler, op, SocketOperation.None);
 }
Пример #4
0
 public void initialize(EventHandler handler)
 {
     // Nothing to do.
 }
Пример #5
0
        public void finish(EventHandler handler)
        {
            lock(this)
            {
                Debug.Assert(!_destroyed);

                //
                // If there are no pending asynchronous operations, we can call finish on the handler now.
                //
                if(handler._pending == 0)
                {
                    handler._registered = SocketOperation.None;
                    executeNonBlocking(() =>
                       {
                           ThreadPoolCurrent current = new ThreadPoolCurrent(this, handler, SocketOperation.None);
                           handler.finished(ref current);
                       });
                }
                else
                {
                    handler._finish = true;
                }
            }
        }
Пример #6
0
 public void finish(EventHandler handler)
 {
     _m.Lock();
     try
     {
         Debug.Assert(!_destroyed);
         if(handler._pending == 0)
         {
             handler._registered = SocketOperation.None;
             executeNonBlocking(delegate()
                                {
                                    ThreadPoolCurrent current = 
                                        new ThreadPoolCurrent(this, handler, SocketOperation.None);
                                    handler.finished(ref current);
                                });
         }
         else
         {
             handler._finish = true;
         }
     }
     finally
     {
         _m.Unlock();
     }
 }
Пример #7
0
 public void update(EventHandler handler, int remove, int add)
 {
     _m.Lock();
     try
     {
         Debug.Assert(!_destroyed);
         handler._registered = handler._registered & ~remove;
         handler._registered = handler._registered | add;
         if((add & SocketOperation.Read) != 0 && (handler._pending & SocketOperation.Read) == 0)
         {
             handler._pending |= SocketOperation.Read;
             executeNonBlocking(delegate()
                                {
                                    messageCallback(new ThreadPoolCurrent(this, handler, SocketOperation.Read));
                                });
         }
         else if((add & SocketOperation.Write) != 0 && (handler._pending & SocketOperation.Write) == 0)
         {
             handler._pending |= SocketOperation.Write;
             executeNonBlocking(delegate()
                                {
                                    messageCallback(new ThreadPoolCurrent(this, handler, SocketOperation.Write));
                                }); 
         }
     }
     finally
     {
         _m.Unlock();
     }
 }