25 #ifndef __MOTR_LIB_COROUTINE_H__ 26 #define __MOTR_LIB_COROUTINE_H__ 157 #define M0_CO_START(context) \ 159 M0_ASSERT((context)->mc_yield_frame == 0); \ 167 #define M0_CO_END(context) \ 169 int rc = ((context)->mc_yield ? (context)->mc_co_end_ret : 0); \ 171 M0_ASSERT((context)->mc_frame == 0); \ 172 M0_ASSERT((context)->mc_yield_frame == 0); \ 173 m0_co_context_locals_free((context)); \ 183 #define M0_CO_FUN(context, function) \ 186 M0_LOG(M0_DEBUG, "M0_CO_FUN: context=%p yeild=%d", \ 187 context, !!context->mc_yield); \ 188 M0_ASSERT(context->mc_frame < M0_MCC_STACK_NR); \ 189 context->mc_stack[context->mc_frame++] = &&save; \ 191 if (context->mc_yield) { \ 194 m0_co_context_locals_free(context); \ 195 context->mc_frame--; \ 199 #define M0_CO_FRAME_DATA(field) (__frame_data__->field) 205 #define M0_CO_REENTER(context, ...) \ 206 struct foo_context { \ 209 struct foo_context *__frame_data__; \ 210 M0_CO__REENTER((context), __frame_data__); 223 #define M0_CO__REENTER(context, frame_data) \ 225 uint64_t size = sizeof(*frame_data); \ 226 M0_LOG(M0_DEBUG, "M0_CO_REENTER: context=%p yeild=%d", \ 227 context, !!context->mc_yield); \ 228 if (!context->mc_yield) { \ 229 m0_co_context_locals_alloc(context, (size)); \ 230 frame_data = m0_co_context_locals(context); \ 232 M0_ASSERT(context->mc_yield_frame < M0_MCC_STACK_NR); \ 233 frame_data = m0_co_context_locals(context); \ 234 goto *context->mc_stack[context->mc_yield_frame++]; \ 248 #define M0_CO_YIELD_RC(context, rc) \ 251 M0_LOG(M0_DEBUG, "M0_CO_YIELD: context=%p yeild=%d", \ 252 context, !!context->mc_yield); \ 253 context->mc_yield = true; \ 254 context->mc_co_end_ret = (rc); \ 255 M0_ASSERT(context->mc_frame < M0_MCC_STACK_NR); \ 256 context->mc_stack[context->mc_frame++] = &&save; \ 259 M0_ASSERT(context->mc_yield); \ 260 M0_ASSERT(context->mc_frame == context->mc_yield_frame); \ 261 context->mc_yield = false; \ 262 context->mc_yield_frame = 0; \ 263 context->mc_frame--; \ 266 #define M0_CO_YIELD(context) M0_CO_YIELD_RC(context, -EAGAIN)
M0_INTERNAL void m0_co_context_fini(struct m0_co_context *context)
M0_INTERNAL void m0_co_op_reset(struct m0_co_op *op)
M0_INTERNAL void m0_co_op_init(struct m0_co_op *op)
struct m0_sm_group co_sm_group
M0_INTERNAL void m0_co_op_fini(struct m0_co_op *op)
M0_INTERNAL int m0_co_op_tick_ret(struct m0_co_op *op, struct m0_fom *fom, int next_state)
M0_INTERNAL void m0_co_context_locals_alloc(struct m0_co_context *context, uint64_t size)
M0_INTERNAL void * m0_co_context_locals(struct m0_co_context *context)
struct m0_co_locals_allocator mc_alloc
M0_INTERNAL void m0_co_op_active(struct m0_co_op *op)
M0_INTERNAL int m0_co_context_init(struct m0_co_context *context)
void * mc_stack[M0_MCC_STACK_NR]
struct m0_co_la_item la_items[M0_MCC_STACK_NR]
void * mc_locals[M0_MCC_STACK_NR]
M0_INTERNAL void m0_co_context_locals_free(struct m0_co_context *context)
M0_INTERNAL void m0_co_op_done(struct m0_co_op *op)