00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _P_UnixEThread_h_
00032 #define _P_UnixEThread_h_
00033
00034 #include "I_EThread.h"
00035 #include "I_EventProcessor.h"
00036
00037 const int DELAY_FOR_RETRY = HRTIME_MSECONDS(10);
00038
00039 TS_INLINE Event *
00040 EThread::schedule_spawn(Continuation * cont)
00041 {
00042 Event *e = EVENT_ALLOC(eventAllocator, this);
00043 return schedule(e->init(cont, 0, 0));
00044 }
00045
00046 TS_INLINE Event *
00047 EThread::schedule_imm(Continuation * cont, int callback_event, void *cookie)
00048 {
00049 Event *e =::eventAllocator.alloc();
00050 e->callback_event = callback_event;
00051 e->cookie = cookie;
00052 return schedule(e->init(cont, 0, 0));
00053 }
00054
00055 TS_INLINE Event *
00056 EThread::schedule_imm_signal(Continuation * cont, int callback_event, void *cookie)
00057 {
00058 Event *e =::eventAllocator.alloc();
00059 e->callback_event = callback_event;
00060 e->cookie = cookie;
00061 return schedule(e->init(cont, 0, 0), true);
00062 }
00063
00064 TS_INLINE Event *
00065 EThread::schedule_at(Continuation * cont, ink_hrtime t, int callback_event, void *cookie)
00066 {
00067 Event *e =::eventAllocator.alloc();
00068 e->callback_event = callback_event;
00069 e->cookie = cookie;
00070 return schedule(e->init(cont, t, 0));
00071 }
00072
00073 TS_INLINE Event *
00074 EThread::schedule_in(Continuation * cont, ink_hrtime t, int callback_event, void *cookie)
00075 {
00076 Event *e =::eventAllocator.alloc();
00077 e->callback_event = callback_event;
00078 e->cookie = cookie;
00079 return schedule(e->init(cont, ink_get_based_hrtime() + t, 0));
00080 }
00081
00082 TS_INLINE Event *
00083 EThread::schedule_every(Continuation * cont, ink_hrtime t, int callback_event, void *cookie)
00084 {
00085 Event *e =::eventAllocator.alloc();
00086 e->callback_event = callback_event;
00087 e->cookie = cookie;
00088 return schedule(e->init(cont, ink_get_based_hrtime() + t, t));
00089 }
00090
00091 TS_INLINE Event *
00092 EThread::schedule(Event * e, bool fast_signal)
00093 {
00094 e->ethread = this;
00095 ink_assert(tt == REGULAR);
00096 if (e->continuation->mutex)
00097 e->mutex = e->continuation->mutex;
00098 else
00099 e->mutex = e->continuation->mutex = e->ethread->mutex;
00100 ink_assert(e->mutex.m_ptr);
00101 EventQueueExternal.enqueue(e, fast_signal);
00102 return e;
00103 }
00104
00105 TS_INLINE Event *
00106 EThread::schedule_imm_local(Continuation * cont, int callback_event, void *cookie)
00107 {
00108 Event *e = EVENT_ALLOC(eventAllocator, this);
00109 e->callback_event = callback_event;
00110 e->cookie = cookie;
00111 return schedule_local(e->init(cont, 0, 0));
00112 }
00113
00114 TS_INLINE Event *
00115 EThread::schedule_at_local(Continuation * cont, ink_hrtime t, int callback_event, void *cookie)
00116 {
00117 Event *e = EVENT_ALLOC(eventAllocator, this);
00118 e->callback_event = callback_event;
00119 e->cookie = cookie;
00120 return schedule_local(e->init(cont, t, 0));
00121 }
00122
00123 TS_INLINE Event *
00124 EThread::schedule_in_local(Continuation * cont, ink_hrtime t, int callback_event, void *cookie)
00125 {
00126 Event *e = EVENT_ALLOC(eventAllocator, this);
00127 e->callback_event = callback_event;
00128 e->cookie = cookie;
00129 return schedule_local(e->init(cont, ink_get_based_hrtime() + t, 0));
00130 }
00131
00132 TS_INLINE Event *
00133 EThread::schedule_every_local(Continuation * cont, ink_hrtime t, int callback_event, void *cookie)
00134 {
00135 Event *e = EVENT_ALLOC(eventAllocator, this);
00136 e->callback_event = callback_event;
00137 e->cookie = cookie;
00138 return schedule_local(e->init(cont, ink_get_based_hrtime() + t, t));
00139 }
00140
00141 TS_INLINE Event *
00142 EThread::schedule_local(Event * e)
00143 {
00144 if (tt != REGULAR) {
00145 ink_assert(tt == DEDICATED);
00146 return eventProcessor.schedule(e, ET_CALL);
00147 }
00148 if (!e->mutex.m_ptr) {
00149 e->ethread = this;
00150 e->mutex = e->continuation->mutex;
00151 } else {
00152 ink_assert(e->ethread == this);
00153 }
00154 e->globally_allocated = false;
00155 EventQueueExternal.enqueue_local(e);
00156 return e;
00157 }
00158
00159 TS_INLINE EThread *
00160 this_ethread()
00161 {
00162 return (EThread *) this_thread();
00163 }
00164
00165 TS_INLINE void
00166 EThread::free_event(Event * e)
00167 {
00168 ink_assert(!e->in_the_priority_queue && !e->in_the_prot_queue);
00169 e->mutex = NULL;
00170 EVENT_FREE(e, eventAllocator, this);
00171 }
00172
00173 #endif