2. Async IO

Start cpp section to faio/faio_asyncio.hpp[1 /1 ]
     1: #line 93 "./lpsrc/flx_faio.pak"
     2: #ifndef __FLX_FAIO_ASYNCIO_H__
     3: #define __FLX_FAIO_ASYNCIO_H__
     4: #include <flx_faio_config.hpp>
     5: #include "pthread_sleep_queue.hpp"
     6: 
     7: #include "demux_demuxer.hpp"        // sel_param, demuxer base
     8: #include "flx_rtl.hpp"
     9: 
    10: namespace flx { namespace faio {
    11: 
    12: struct FAIO_EXTERN finote_t
    13: {
    14:   virtual void signal()=0;
    15:   virtual ~finote_t(){}
    16: };
    17: 
    18: class FAIO_EXTERN wakeup_fthread_t : public finote_t
    19: {
    20:   rtl::fthread_t *f;
    21:   pthread::sleep_queue_t *q;
    22: public:
    23:   wakeup_fthread_t(pthread::sleep_queue_t *q_a, rtl::fthread_t *f_a) : f(f_a), q(q_a) {}
    24:   void signal () { q->enqueue(f); }
    25: };
    26: 
    27: 
    28: class FAIO_EXTERN flx_driver_request_base {
    29:     finote_t *fn;
    30:     virtual bool start_async_op_impl() = 0;
    31: public:
    32:     flx_driver_request_base() : fn(0) {}
    33:     virtual ~flx_driver_request_base() {}       // so destructors work
    34: 
    35:     // returns finished flag (async may fail or immediately finish)
    36:     void start_async_op(finote_t *fn_a);
    37:     void notify_finished();
    38: };
    39: 
    40: }} // namespace faio, flx
    41: #endif  // __ASYNCIO__
    42: 
    43: 
End cpp section to faio/faio_asyncio.hpp[1]
Start cpp section to faio/faio_asyncio.cpp[1 /1 ]
     1: #line 137 "./lpsrc/flx_faio.pak"
     2: #include <assert.h>
     3: #include "faio_asyncio.hpp"
     4: 
     5: namespace flx { namespace faio {
     6: 
     7: void flx_driver_request_base:: start_async_op(finote_t *fn_a)
     8: {
     9:   //fprintf(stderr,"start async op %p, set fn = %p\n",this,fn_a);
    10:   fn = fn_a;
    11:   bool completed =  start_async_op_impl();
    12:   if(completed)
    13:   {
    14:     //fprintf(stderr,"instant complete\n");
    15:     notify_finished();
    16:   }
    17:   else
    18:   {
    19:     //fprintf(stderr,"Pending\n");
    20:   }
    21: }
    22: 
    23: void flx_driver_request_base:: notify_finished()
    24: {
    25:   //fprintf(stderr, "faio_req=%p, Notify %p\n", this,fn);
    26:   assert(fn!=0);
    27:   finote_t *fin = fn;
    28:   fn=0;
    29:   fin->signal();
    30:   delete fin;
    31:   //fprintf(stderr, "faio_req=%p, FINISHED\n",this);
    32: }
    33: 
    34: }}
    35: 
End cpp section to faio/faio_asyncio.cpp[1]