public ThreadPoolCurrent(ThreadPool threadPool, EventHandler handler, int op) { _threadPool = threadPool; _handler = handler; operation = op; completedSynchronously = false; }
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)); }); } } }
public void unregister(EventHandler handler, int op) { update(handler, op, SocketOperation.None); }
public void initialize(EventHandler handler) { // Nothing to do. }
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; } } }
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(); } }
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(); } }