Exemplo n.º 1
0
      public IAsyncResult BeginWrite(ReaderWriterGateCallback callback, Object state,
        AsyncCallback asyncCallback, Object asyncState) {
         AsyncResult<Object> ar = new AsyncResult<Object>(asyncCallback, asyncState);
         ReaderWriterGateReleaser releaser = new ReaderWriterGateReleaser(callback, this, false, state, ar);
         m_syncLock.Enter(true);
         switch (m_state) {
            case ReaderWriterGateStates.Free:             // If Free "RFW -> OBW, invoke, return
            case ReaderWriterGateStates.ReservedForWriter:
               m_state = ReaderWriterGateStates.OwnedByWriter;
               ThreadPool.QueueUserWorkItem(releaser.Invoke);
               break;

            case ReaderWriterGateStates.OwnedByReaders:   // If OBR | OBRAWP -> OBRAWP, queue, return
            case ReaderWriterGateStates.OwnedByReadersAndWriterPending:
               m_state = ReaderWriterGateStates.OwnedByReadersAndWriterPending;
               m_qWriteRequests.Enqueue(releaser);
               break;

            case ReaderWriterGateStates.OwnedByWriter:   // If OBW, queue, return
               m_qWriteRequests.Enqueue(releaser);
               break;
         }
         m_syncLock.Leave();
         return ar;
      }
Exemplo n.º 2
0
        public IAsyncResult BeginWrite(ReaderWriterGateCallback callback, Object state,
                                       AsyncCallback asyncCallback, Object asyncState)
        {
            AsyncResult <Object>     ar       = new AsyncResult <Object>(asyncCallback, asyncState);
            ReaderWriterGateReleaser releaser = new ReaderWriterGateReleaser(callback, this, false, state, ar);

            m_syncLock.Enter(true);
            switch (m_state)
            {
            case ReaderWriterGateStates.Free:             // If Free "RFW -> OBW, invoke, return
            case ReaderWriterGateStates.ReservedForWriter:
                m_state = ReaderWriterGateStates.OwnedByWriter;
                ThreadPool.QueueUserWorkItem(releaser.Invoke);
                break;

            case ReaderWriterGateStates.OwnedByReaders:   // If OBR | OBRAWP -> OBRAWP, queue, return
            case ReaderWriterGateStates.OwnedByReadersAndWriterPending:
                m_state = ReaderWriterGateStates.OwnedByReadersAndWriterPending;
                m_qWriteRequests.Enqueue(releaser);
                break;

            case ReaderWriterGateStates.OwnedByWriter:   // If OBW, queue, return
                m_qWriteRequests.Enqueue(releaser);
                break;
            }
            m_syncLock.Leave();
            return(ar);
        }
Exemplo n.º 3
0
 internal ReaderWriterGateReleaser(ReaderWriterGateCallback callback, ReaderWriterGate gate,
                                   Boolean reader, Object state, AsyncResult <Object> ar)
 {
     m_callback    = callback;
     m_gate        = gate;
     m_flags       = reader ? ReleaserFlags.Reader : ReleaserFlags.Writer;
     m_state       = state;
     m_asyncResult = ar;
 }
Exemplo n.º 4
0
 /// <summary>Initiates an asynchronous write operation.</summary>
 /// <param name="callback">The method that will perform the write operation.</param>
 /// <param name="asyncCallback">An optional asynchronous callback, to be called when the operation completes.</param>
 /// <returns>A System.IAsyncResult that represents the asynchronous operation, which could still be pending.</returns>
 public IAsyncResult BeginWrite(ReaderWriterGateCallback callback, AsyncCallback asyncCallback) {
    return BeginWrite(callback, null, asyncCallback, null);
 }
Exemplo n.º 5
0
      internal ReaderWriterGateReleaser(ReaderWriterGateCallback callback, ReaderWriterGate gate,
         Boolean reader, Object state, AsyncResult<Object> ar) {

         m_callback = callback;
         m_gate = gate;
         m_flags = reader ? ReleaserFlags.Reader : ReleaserFlags.Writer;
         m_state = state;
         m_asyncResult = ar;
      }
Exemplo n.º 6
0
 /// <summary>Initiates an asynchronous write operation.</summary>
 /// <param name="callback">The method that will perform the write operation.</param>
 /// <param name="asyncCallback">An optional asynchronous callback, to be called when the operation completes.</param>
 /// <returns>A System.IAsyncResult that represents the asynchronous operation, which could still be pending.</returns>
 public IAsyncResult BeginWrite(ReaderWriterGateCallback callback, AsyncCallback asyncCallback)
 {
     return(BeginWrite(callback, null, asyncCallback, null));
 }