struct rain_message_queue* rain_message_queue_new() { struct rain_message_queue * mq = malloc(sizeof(struct rain_message_queue)); wod_queue_init(&mq->r_queue,sizeof(struct rain_ctx_message)); rain_mutex_init(&mq->mtx); return mq; }
int rain_timer_init() { mgr.head = NULL; rain_mutex_init(&mgr.mtx); mgr.runhead = NULL; mgr.min = MIN_SLEEP; return RAIN_OK; }
int rain_lifequeue_int() { LQ = malloc(sizeof(rain_lq_t)); #ifdef PTHREAD_LOCK pthread_mutex_init(&LQ->mtx,NULL); pthread_cond_init(&LQ->con,NULL); #else rain_mutex_init(&LQ->mtx); #endif return rain_queue_init(&LQ->r_queue,sizeof(routine_t)); }
int rain_ctx_init(int rainid) { H = malloc(sizeof(struct rain_handle)); assert(H); struct rain_handle* h = H; memset(h->ppctx,0,sizeof(void *)*CTX_SET); h->num_used = 0; rain_mutex_init(&h->mtx); h->rainid =rainid; h->cut_index = 1; return 0; }
struct rain_ctx * rain_ctx_new(rain_routine_t prid, const char * mod_name,const char *args) { if(IS_FULL(H)){ return NULL; } struct rain_moudle *mod = rain_module_query(mod_name); if(!mod){ RAIN_LOG(0,"MODE_QUERY:modname:%s",mod_name); return NULL; } //INIT struct rain_ctx *ctx = malloc(sizeof(struct rain_ctx)); ctx->mod = mod; ctx->bdis = 0; ctx->recv = NULL; ctx->recv_rsp = NULL; ctx->link = NULL; ctx->session = 0; ctx->timeoutfn = NULL; ctx->nexttickfn = NULL; rain_mutex_init(&ctx->mtx); wod_array_init(&ctx->arr,sizeof(rain_routine_t)); ctx->msgQue = rain_message_queue_new(); ctx->bmain = false; _ctx_genid(ctx); ctx->ref = 1; ctx->bexit = 0; ctx->prid = prid; ctx->arg = rain_module_instance_init(mod,ctx,args); //EXEC; if(ctx->arg == NULL){ RAIN_LOG(0,"RAIN_MAIN_FIALED:modname:%s args:%s",mod_name,args); rain_ctx_unref(ctx); return NULL; } __sync_bool_compare_and_swap(&ctx->bmain,false,true); if(rain_message_queue_size(ctx->msgQue) > 0){ if(__sync_bool_compare_and_swap(&ctx->bdis,0,1)){ rain_life_queue_push(ctx->rid); } } RAIN_LOG(0,"LAUNCH.ctx(%x.%s).arguments:%s",ctx->rid,mod_name,args); return ctx; }