Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 #if !defined(_P_Freer_h_)
00025 #define _P_Freer_h_
00026 
00027 #include "libts.h"
00028 #include "I_Tasks.h"
00029 
00030 
00031 
00032 
00033 
00034 template<class C> struct DeleterContinuation: public Continuation
00035 {
00036 public:                        
00037   C * p;
00038   int dieEvent(int event, void *e)
00039   {
00040     (void) event;
00041     (void) e;
00042     if (p)
00043       delete p;
00044     delete this;
00045       return EVENT_DONE;
00046   }
00047   DeleterContinuation(C * ap):Continuation(new_ProxyMutex()), p(ap)
00048   {
00049     SET_HANDLER(&DeleterContinuation::dieEvent);
00050   }
00051 };
00052 
00053 template<class C> TS_INLINE void
00054 new_Deleter(C * ap, ink_hrtime t)
00055 {
00056   eventProcessor.schedule_in(new DeleterContinuation<C> (ap), t, ET_TASK);
00057 }
00058 
00059 template<class C> struct FreeCallContinuation: public Continuation
00060 {
00061 public:                        
00062   C * p;
00063   int dieEvent(int event, void *e)
00064   {
00065     (void) event;
00066     (void) e;
00067     p->free();
00068     delete this;
00069       return EVENT_DONE;
00070   }
00071   FreeCallContinuation(C * ap):Continuation(NULL), p(ap)
00072   {
00073     SET_HANDLER(&FreeCallContinuation::dieEvent);
00074   }
00075 };
00076 
00077 template<class C> TS_INLINE void
00078 new_FreeCaller(C * ap, ink_hrtime t)
00079 {
00080   eventProcessor.schedule_in(new FreeCallContinuation<C> (ap), t, ET_TASK);
00081 }
00082 
00083 struct FreerContinuation;
00084 typedef int (FreerContinuation::*FreerContHandler) (int, void *);
00085 
00086 struct FreerContinuation: public Continuation
00087 {
00088   void *p;
00089 
00090   int dieEvent(int event, Event * e)
00091   {
00092     (void) event;
00093     (void) e;
00094     ats_free(p);
00095     delete this;
00096     return EVENT_DONE;
00097   }
00098 
00099   FreerContinuation(void *ap):Continuation(NULL), p(ap)
00100   {
00101     SET_HANDLER((FreerContHandler) & FreerContinuation::dieEvent);
00102   }
00103 };
00104 
00105 TS_INLINE void
00106 new_Freer(void *ap, ink_hrtime t)
00107 {
00108   eventProcessor.schedule_in(new FreerContinuation(ap), t, ET_TASK);
00109 }
00110 
00111 template<class C> struct DereferContinuation: public Continuation
00112 {
00113   C *p;
00114 
00115   int dieEvent(int, Event *)
00116   {
00117     p->refcount_dec();
00118     if (REF_COUNT_OBJ_REFCOUNT_DEC(p) == 0) {
00119       delete p;
00120     }
00121 
00122     delete this;
00123     return EVENT_DONE;
00124   }
00125 
00126   DereferContinuation(C * ap):Continuation(NULL), p(ap)
00127   {
00128     SET_HANDLER(&DereferContinuation::dieEvent);
00129   }
00130 };
00131 
00132 template<class C> TS_INLINE void
00133 new_Derefer(C * ap, ink_hrtime t)
00134 {
00135   eventProcessor.schedule_in(new DereferContinuation<C> (ap), t, ET_TASK);
00136 }
00137 
00138 #endif